首页 > 解决方案 > How do Jenkins pipeline builds determine the workspace folder?

问题描述

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?

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

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

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

WORKSPACE=xxx\yyy\jobname@2

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.

So my questions are:

Thanks for any insights!

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

标签: jenkinsjenkins-pipeline

解决方案


工作空间分配在WorkspaceList.java中完成。

可以在工作空间上获取锁,然后导致@<number>后缀,请参阅allocate最后声明This method doesn't block prolonged amount of time. Whenever a desired workspace is in use, the unique variation is added.Check out the COMBINATORvariable 的方法。

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

编辑:错过了你的其他问题。正如您在此源文件中看到的,执行程序编号与工作空间命名无关。唯一的原因是当基本工作空间路径上没有后缀+数字(inUse.get(candidate.getRemote());。因此,一旦工作空间在使用中,它只会检查下一个候选者,@n+1 据我所知詹金斯将重用工作空间。根据您的 scm 结帐策略,您可能甚至考虑在使用deleteDir构建之前手动清理工作区,以确保不会产生副作用。


推荐阅读