Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get files in jenkins pipeline file?

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

like image 347
vijay Avatar asked Jan 30 '17 10:01

vijay


People also ask

How do I access Jenkins files?

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.

How do I read a text file in Jenkins pipeline?

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.

How do I get a pipeline script in Jenkins?

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.

How do I download files from Jenkins workspace?

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.


1 Answers

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().

like image 67
afxentios Avatar answered Oct 09 '22 16:10

afxentios