Jenkins管道构建如何确定工作空间文件夹? [英] How do Jenkins pipeline builds determine the workspace folder?

查看:472
本文介绍了Jenkins管道构建如何确定工作空间文件夹?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Jenkins管道中,当在特定节点上运行构建时,会在该代理上分配工作区.我们没有设置工作空间路径,因此它是自动确定的.我了解,当同一作业在同一代理上同时运行时,工作区必须包含执行者编号以隔离构建.

In Jenkins pipeline, when a build is run on a particular node, a workspace is allocated on that agent. We do not set the workspace path, so it's automatically determined. I understand that the workspace must contain the executor number to isolate builds when the same job is running concurrently on the same agent.

但是...工作空间路径到底是如何构建的?

But... How exactly is the workspace path constructed?

我们的构建被分配给一个特定的节点(具有4个执行器),并且被配置为不允许并行构建.通常分配给它:

Our build is assigned to a particular node (with 4 executors) and is configured to not allow concurrent builds. Usually it was assigned:

EXECUTOR_NUMBER=1
WORKSPACE=xxx\yyy\jobname

从某个时候开始,该构建开始在执行程序2上运行,但仍使用与以前相同的工作空间.

At some point, the build started to run on executor 2, but still using the same workspace as before.

此后,该构建再次在执行程序1上运行,但现在使用

Later on, the build was again running on executor 1, but now using

WORKSPACE=xxx\yyy\jobname@2

破坏了构建,因为它无法处理路径中的'@'符号.从那时起,即使在将构建计算机上的执行程序的数量设置为1之后,该构建仍继续使用该工作空间,手动删除代理的工作空间目录等.

which broke the build because it can't handle the '@' sign in the path. From that point on, the build continued to use that workspace, even after setting number of executors on the build machine to 1, manually removing the agent's workspace dir etc.

所以我的问题是:

  • 如何准确确定工作空间路径?为什么突然出现@ 2后缀?
  • Jenkins是否重新使用先前的工作空间,而不管执行者的编号是多少?
  • 如果是,此信息存储在哪里?我在作业配置中找不到与上次使用的工作空间路径相关的任何内容...

感谢您的见解!

我们正在使用Jenkins LTS 2.107.2和最新的Pipeline插件(我不知道哪个版本特别有趣).

We're using Jenkins LTS 2.107.2 and up-to-date Pipeline plugins (I don't know which version is of special interest).

推荐答案

工作空间分配在在工作空间上可能会获取一些锁,这些锁随后会导致后缀为@<number>,请参见allocate方法,该方法指出This method doesn't block prolonged amount of time. Whenever a desired workspace is in use, the unique variation is added.最后检查COMBINATOR变量.

There can be locks acquired on a workspace which then leads to the @<number>suffix, see the allocate method which states This method doesn't block prolonged amount of time. Whenever a desired workspace is in use, the unique variation is added.Check out the COMBINATOR variable at the end.

如果这真的是一个大问题,您可以自己编译jenkins并更改此分隔符.减少麻烦的可能是自己分配工作空间,即在选择自己的路径时以某种方式检查它们是否未使用(或使用一些时间戳后缀),但要注意,此分隔符还用于其他可能使用的路径,即何时使用全局共享库,它们使用诸如workspace@script等的路径.

If this is really such a big issue you could compile jenkins yourself and change this separator. Less hassle would probably be to allocate workspaces yourself, i.e. choose your own paths whilst somehow checking they are not in use (or using some timestamp suffix), but be aware that this separator is also used for some other paths that might be used i.e. when using Global Shared Libraries which use paths like workspace@script etc.

错过了您的其他问题.正如您在此源文件中看到的那样,执行器编号与工作空间命名无关.唯一的原因是基本工作区路径上有一些没有后缀+数字(inUse.get(candidate.getRemote());的锁.因此,一旦使用了工作区,它将仅使用@n+1检查下一个候选对象. 据我所知,詹金斯将重用工作空间.根据您的scm结帐策略,您甚至可以考虑在 deleteDir ,只是为了确保不会产生副作用.

Missed your other questions. As you can see in this sourcefile, executor number is irrelevant for workspace naming. Sole reason is when some lock is on the base workspace path without suffix+number(inUse.get(candidate.getRemote());. So once a workspace is inUse it will just check the next candidate with @n+1 As far as i know Jenkins will reuse workspaces. Depending on your scm checkout strategy you might even consider manually cleaning a workspace before your build with deleteDir, just to be sure to not get side-effects.

这篇关于Jenkins管道构建如何确定工作空间文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆