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.
- Why isn't it recognizing the file in the first snippet, but does recognize it in the second one?
- Is there a way to make the upper snippet works as expected in Jenkins?
Fileclass only works correctly for paths on the Jenkins master, and not the build agents. Is this file on the master?