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