I am trying the retrieve the output/status of a variable available in bat to a jenkins pipeline by setting env variable initially as true.
My expectation is that based on the value of a variable assigned inside bat (i.e., status=false), next stage could not be executed since when expression is given in that stage:
pipeline {
agent any
environment{
STATUS='TRUE'
}
stages {
stage('test1') {
steps {
bat '''set status=FALSE
echo %status%'''
echo "$status"
}
}
stage('test2') {
when{
environment name: 'STATUS', value: 'TRUE'
}
steps {
input message: 'Push', ok: 'GO!!'
}
}
}
}
The output which I am currently getting is o/p: false for bat execution and next step provides the output as true.
The echo "$status" is in pipeline, where as the environment STATUS changes are done on the node. AFAIK this won't get reflected in the pipeline itself.
What you could do is use returnStdout: true and maintain this variable state in the pipeline
def script = '''set status=FALSE
echo %status%'''
def status = bat(script: script, returnStdout: true)
echo "$status"
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