I am wanting to pass variables between stages in a Jenkinsfile and am doing it as people suggest, by writing to a file then parsing it.
stage('1') {
steps {
sh "echo value > var.txt"
script {
VALUE = readFile('var.txt')
}
}
}
stage('2') {
steps {
sh "echo ${VALUE} && echo 'ok'"
}
}
However, I am getting some form of new line character at the end of ${VALUE}
that means I am trying to execute 2 lines and the &&
is causing the stage to barf. I've tried piping through tr -d '\r\n'
but it doesn't seem to do anything.
Any Jenkins job or pipeline can be parameterized. All we need to do is check the box on the General settings tab, “This project is parameterized”: Then we click the Add Parameter button.
The sh step assumes the system is Unix/Linux-based, for Windows-based systems the bat could be used instead. The sh step invokes the make command and will only continue if a zero exit code is returned by the command. Any non-zero exit code will fail the Pipeline.
Pipeline: Nodes and Processes. bat : Windows Batch Script. node : Allocate node. powershell : Windows PowerShell Script. pwsh : PowerShell Core Script.
input : Wait for interactive input. This step pauses Pipeline execution and allows the user to interact and control the flow of the build. Only a basic "proceed" or "abort" option is provided in the stage view. You can optionally request information back, hence the name of the step.
I ran into this problem as well for my Jenkins file that is a groovy script, and this is what helped me get rid of the EOL / CR characters at the end of the value I wanted to use:
VALUE = readFile('var.txt').trim()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With