Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Retrieve output/status of a variable from batch file to jenkins pipeline

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.

like image 815
TryandCatch Avatar asked Nov 01 '25 11:11

TryandCatch


1 Answers

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" 
like image 81
hakamairi Avatar answered Nov 03 '25 10:11

hakamairi