I am trying to use an if statement in my Jenkinsfile for multi branch pipeline project. For the sake of this question, assume I have a text file in my current directory called 'scan.txt'. The text file is generated with a bash command
echo "False" > scan.txt
So the only content is the string "False"
I set an arbitrary environment variable in my Jenkinsfile to the contents of scan.txt like so:
script {
env.TEXT = readFile 'scan.txt'
}
If I do
echo "${env.TEXT}"
outside the script block then the jenkins console shows False for that step, as expected.
However, all of my attempts at checking if it is equal to "False" have failed. I have tried the following immediately after the script block:
if (env.TEXT.equals("False")) {
//do something
}
if (env.TEXT.matches("False")) {
//do something
}
if (env.TEXT == "False") {
//do something
}
and none of them work. All of these conditions are boolean false. The documentation for the read file pipeline step states it returns a string of the file contents https://jenkins.io/doc/pipeline/steps/workflow-basic-steps/#code-readfile-code-read-file-from-workspace so I'm not sure what's going on here. Does anyone have any insights?
Thanks