Changing workspace directory in Jenkins

Jun 24, 2023 · 1 min read · Post a comment

In Jenkins, each stage in a pipeline is executed in a separate workspace directory. The workspace is a local directory on the Jenkins agent where the pipeline is running. Each stage can have its own workspace, and the workspace is typically isolated from other stages. So, what if we want to change to some subdirectory?! There’s a function for it already.


  • Jenkins


Let’s say you want to create a subdirectory called newsubdir (very creative) and execute pwd in it. It should look like this:

    sh "pwd"

Note: newsubdir can be relative or absolute path.


In case you face any issues, feel free to leave a comment below and if you find this tutorial useful, follow our official channel on Telegram.