I want to get all files name with some pattern from work-space through jenkins pipeline script.
Get list of pjs files from my work-space and store to array
If you're running Jenkins on a Windows server, AND your desktop is on the same system, your desktop path will look like "C:\Users\username\Desktop". In either case, that's the path you'll need to use in your Jenkins job.
In the first stage we create a variable called data that holds some text and the we use the writeFile function to write it out to a file. Then we execute ls as an external program using sh. In the second stage we use the readFile function to read in the content of the file.
To create a simple pipeline from the Jenkins interface, perform the following steps: Click New Item on your Jenkins home page, enter a name for your (pipeline) job, select Pipeline, and click OK. In the Script text area of the configuration screen, enter your pipeline syntax.
You can use the access to workspace via URL (http://<servername:port>/job/<jobname>/ws/), but you'll have to copy the file over to the workspace out of the relevant build before the build is over. Save this answer. Show activity on this post. Save this answer.
You can use findFiles:
files = findFiles(glob: '**/.pjs')
Find files in the current working directory. The step returns an array of file info objects.
These file info objects have name
as a property, so you can easily get the name of the files as below:
eg. files[0].name
Note:
Make sure that you in the the correct directory (workspace) using pwd() and dir().
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