Reputation: 95948
I have the following stages in my test.groocy
pipeline:
stages {
stage('Test') {
steps {
env.SOME_VAR = new File("settings.gradle")
.readLines()
.findAll { someLogic }
.collect { it =~ /.*'(.*)'/ }
echo "got: ${SOME_VAR}"
}
}
}
But I'm getting:
java.io.FileNotFoundException: settings.gradle (No such file or directory)
If I change the code to:
stages {
stage('Test') {
steps {
sh(returnStdout: true,
script: '''#!/bin/bash
cat settings.gradle''')
}
}
}
I can see the file's content.
Upvotes: 0
Views: 125
Reputation: 28564
sh
, as other Jenkins steps, started in current workspace directory.
So, you could replace native java/groovy new File
with Jenkins readFile
and the rest of your code should work.
readFile("settings.gradle").readLines()...
Or specify the full path for new File
new File("${WORKSPACE}/settings.gradle").readLines()...
Upvotes: 1