-1

I have a Jenkinsfile where I want to apply conditional cases. But I can't assign the exit status of ./*sh output to a variable where I use for if case.

 `environment {
    //This variable need be tested as string
    doError = '0'

}

stage('Run_Tests') {
        steps {
            sh 'chmod +x test.sh'
            doerror = sh './test.sh' 
        }
    }

    stage('Success') {
        when {
            expression { doError == '0' }
        }
        steps {
            echo "ok"
        }
    }
    stage('fail') {
        when {
            expression { doError == '1' }
        }
        steps {
            echo "Failed"
        }
    }`  

sh './test.sh' works fine but i cant assighn the exit value (i define it in .sh to be 0 or 1) like this doerror = sh './test.sh' do not work.

1 Answers1

0

returnStdout allows your script to return the output inside your pipeline and assign it to a variable

doError = sh(script: 'test', returnStdout: true)
robertobatts
  • 965
  • 11
  • 22