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.
dir : Change current directory Change current directory. Any step inside the dir block will use this directory as current and any relative path will use it as base path.
def cmd=new CommandShell() println cmd. execute("cd /d c:\\") println cmd. execute("dir") // Will be the dir of c:\ I wrote a groovy class like this once, it's a lot of experimenting and your instance can be trashed by commands like "exit" but it's possible.
Step #1: From within the desired folder, click “New Item” to create a new item (job/folder). In this case we're using the “Finance” folder we created in the previous task. Step #2: Enter a name in the textbox and select “Freestyle project” and click “OK” to create the job.
You can use the dir step, example:
dir("folder") { sh "pwd" }
The folder
can be relative or absolute path.
The dir
wrapper can wrap, any other step, and it all works inside a steps
block, for example:
steps { sh "pwd" dir('your-sub-directory') { sh "pwd" } sh "pwd" }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With