Home > Net >  Jenkins cd to a folder with pattern?
Jenkins cd to a folder with pattern?

Time:02-03

Here is the folder structure I have.

Workspace folder: D:\Node\MyNode\

  1. When Jenkins build runs on a node, the files from scm gets downloaded to the following folder: D:\Node\MyNode\xx_development

I need to do cd to the folder "xx_development" and this name xx can change for different strasms (RTC) but "_development" remains same.

how can I do cd to a folder with (*development) using a pipeline script?

Edit: I am using windows Nodes for Jenkins.

CodePudding user response:

To change the current directory to the folder with the pattern *_development, you can use the following script:

def Folder = sh(returnStdout: true, script: 'ls -d */ | grep "_development"').trim() 

sh "cd ${Folder}"

As you can see, the first line ls -d */ | grep "_development", which lists all directories in the folder and filters by the pattern _development. If there are any leading or trailing whitespaces, they are removed using the trim().

The second line changes the current directory to the folder stored in the Folder variable.

  • Related