amit kumar
amit kumar

Reputation: 15

Jenkins stage exited with code 1 and passing stage

in my pipeline one of the stage is exited with code 1 and still pipeline is passing. I want to fail the pipeline stage with exception when it is exiting with code 1.

Here is stage code:

stage('Stage A'){
  steps{
    script{
      container('A'){
        sh "$Command"
                def exitCode = sh 'echo $?'
                if (exitCode == 1) {
                     sh "exit 1"
        }
      }
    }
  }
}

Screenshot link

Upvotes: 1

Views: 624

Answers (1)

ycr
ycr

Reputation: 14594

If you want to error out the Pipeline you can use error signal.

def exitCode = sh script:"$Command", returnStatus:true
if (exitCode == 1) {
     error "Exit code is 1, so erroring out!"
}

Upvotes: 1

Related Questions