Search code examples
jenkinsjenkins-groovycicd

Jenkins: Change Default Name of Allocated Workspace in Node-Block


When using a scripted Jenkins pipeline, is it possible to change the allocated workspace which is allocated automatically by node('myAgent) {...}? Since I care about locking, I currently use the following approach (instead of dir('myWorkspace)):

....
node('myAgent') { ws("ws${env.BUILD_ID}/myWorkspace") { .... } }
...

While this approach is working for me, I get a side effect: The number of allocated workspaces is doubled. This double allocation is caused by the implicit workspace allocation in node('myAgent){...} and the subsequent workspace allocation via ws('myWorkspace){...}.


Solution

  • Sorry, you don't get to pick a name for the default workspace, Jenkins handles that. Here is where it actually happens.

    The default workspace allocated by the node step doesn't have any sources checked out into it automatically, so it's just an empty folder, if you are worried about disk space.