Read files from workspace in multibranch pipeline scm?

64 zobrazení
Přeskočit na první nepřečtenou zprávu

anton kropp

nepřečteno,
13. 12. 2016 17:36:5713.12.16
komu: Jenkins Users
I'm having some issues reading files from the local workspace. As part of my build a set of artifact files are created and I'd like to iterate over them, parse their json contents, and act on it in a pipeline step. However, I can't seem to get reading files from the workspace to work.

My stage looks like:


stage('Push docker containers') {
def slurper = new JsonSlurper()

def files = new File(env.WORKSPACE).listFiles()

for (int i = 0; i < files.size(); i++) {
def file = files[i]
println(file.name)
if (file.name.endsWith(".json")) {
def json = slurper.parse(file)

json.each { key, value ->
// do stuff
}
}
}
}


I keep getting a null pointer on files.size. I've tried to ls the workspace to see whats in it, but nothing shows up.   Whats the recommended approach here?

Thanks
-Anton

Michael Kobit

nepřečteno,
14. 12. 2016 8:04:5614.12.16
komu: Jenkins Users
Your problem is the new File( piece. The pipeline code runs on a flyweight executor on the master, and the various steps can run on allocated nodes. You might be able to do something using FilePath, but I think you could use the findFiles step which would get you some information. You could then use the readFile step to get the file contents into your pipeline execution.

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/fd65242f-f3a7-4ba3-8717-3146639d759a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

anton kropp

nepřečteno,
15. 12. 2016 14:56:0615.12.16
komu: Jenkins Users
I see. I was able to do it with the find files step after installing that plugin. Thanks 
Odpovědět všem
Odpověď autorovi
Přeposlat
0 nových zpráv