Jenkins pipeline how to change to another folder

81

Currently i am using Jenkins pipeline script.

For running one command, I need to access a folder outside its workspace directory.

I tried sh "cd $workspace/", but it returned current workspace folder.

How I can change to root workspace directory and then cd to another folder. Please help.

This question is tagged with jenkins groovy jenkins-pipeline

~ Asked on 2018-09-17 17:01:30

The Best Answer is


157

You can use the dir step, example:

dir("folder") {
    sh "pwd"
}

The folder can be relative or absolute path.

~ Answered on 2018-09-17 17:13:38


21

Use WORKSPACE environment variable to change workspace directory.

If doing using Jenkinsfile, use following code :

dir("${env.WORKSPACE}/aQA"){
    sh "pwd"
}

~ Answered on 2019-08-07 17:40:26


Most Viewed Questions: