Listing files in workspace

1,280 views
Skip to first unread message

Chris Selwyn

unread,
Sep 25, 2013, 4:39:58 AM9/25/13
to job-dsl...@googlegroups.com


Is it possible to list the files in the current workspace?

I can see the streamFileFromWorkspace() and readFileFromWorkspace() methods but I would like to find out the file names before reading them.

I guess that I can use the WORKSPACE variable in conjunction with the eachFile() and eachDir() methods but I was wondering if there was already something better.

Chris

Daniel Spilker

unread,
Sep 25, 2013, 4:58:17 AM9/25/13
to job-dsl...@googlegroups.com
There are no convenience methods for listing files. Using the WORKSPACE variable will only work when your seed job runs on the Jenkins master. Otherwise you will have to use the Jenkins API to access the files on a build node.

Daniel


--
You received this message because you are subscribed to the Google Groups "job-dsl-plugin" group.
To unsubscribe from this group and stop receiving emails from it, send an email to job-dsl-plugi...@googlegroups.com.
To post to this group, send email to job-dsl...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/job-dsl-plugin/715eb61e-d7a2-42d0-8ce9-6b450ae645cb%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.



--

    daniel spilker

    ma...@daniel-spilker.com
    +49.179.1093202
    geschwister-scholl-straße 62, 20251 hamburg
    http://daniel-spilker.com

Chris Selwyn

unread,
Sep 25, 2013, 7:42:11 AM9/25/13
to job-dsl...@googlegroups.com
Thanks for the information.

Thankfully I am working on the master.
I have never worked with slave/build nodes but I may do in the  future so I guess that I should look at how to do this properly.
I have looked at some of the code in the plugin and it is not obvious to me how I should go about accessing the Jenkins API for the job so that I can retrieve files from the master.
Can you give me a hint?

Chris

Chris Selwyn

unread,
Sep 25, 2013, 10:47:32 AM9/25/13
to job-dsl...@googlegroups.com
With much investigation I have found that I can do  the following...

this.jm.build.getWorkspace().list() .each { FilePath fp ->
   println("Found file ${fp.name}")
}

I found the jm.build bit by reading the plugin sources and I would like to know how safe this is in terms of future-proofness of the plugin?
I.e... are the "jm" property if the JobParent class and the "build" property of the JenkinsJobManagement class likely to change?

Chris

Chris Selwyn

unread,
Sep 24, 2013, 7:17:15 AM9/24/13
to job-dsl...@googlegroups.com

Daniel Spilker

unread,
Sep 27, 2013, 3:42:39 AM9/27/13
to job-dsl...@googlegroups.com
Hm, that a hidden feature, which could change in the future. I would rely on the Jenkins API, which is unlikely to change anytime soon.

hudson.FilePath workspace = hudson.model.Executor.currentExecutor().getCurrentWorkspace()



For more options, visit https://groups.google.com/groups/opt_out.

Chris Selwyn

unread,
Sep 27, 2013, 4:41:46 AM9/27/13
to job-dsl...@googlegroups.com
I wondered whether you might say that... that's why I asked.
(And I was so pleased to find such a simple method of finding it!)

Thanks for the hint... It's working just fine.

Chris

Andrew Harmel-Law

unread,
Sep 30, 2013, 8:03:16 AM9/30/13
to job-dsl...@googlegroups.com
Thanks guys.  I'll stick this into the wiki as a new PowerMove.

Andrew Harmel-Law

unread,
Sep 30, 2013, 8:06:00 AM9/30/13
to job-dsl...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages