How do Jenkins pipeline builds determine the workspace folder?
the worksdpaces should not influence your pipeline script.
in my jobs I just do
def workspace = pwd()
at the start of the node scope and uses the workspace as a variable and it works like a charm.
if you open a new node scope you should be aware that it might use a different workspace folder. just open a dir scope :
dir (workspace){
do something
}
with the workspace variable so you could control it in order to use the exact same workspaces as the previous node scope.
I hope it helps
The workspace allocation is done in WorkspaceList.java.
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.
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.
Edit: 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.
Default value for workspace suffix separator (i.e. @) can be changed manually without recompilation of Jenkins using "hudson.slaves.WorkspaceList" property (see this article for details). I.e. in Debian i've changed it to '-' with this line in /etc/default/jenkins:
JAVA_ARGS="-Djava.awt.headless=true -Dhudson.slaves.WorkspaceList=-"