0

In Declarative Pipelines it's not possible to use the try{} catch{} method to parse result of a stage. I need to set the status to UNSTABLE depending on the output of an sh script, any idea of how to achieve it?

Oriol Tauleria
  • 199
  • 1
  • 5

1 Answers1

0

You can use Post-steps feature in Declarative Pipeline. For example:

pipeline {  
    stages {
        stage('some stage') {
            steps {}
        }
    }
    post {
        always {
          // here you can process the output of Shell script and set the build status
        }
        success {
          //Only Success Scenarios
        }
        failure {
         //Only when Failure happens
        }
    }
}
CGS
  • 2,782
  • 18
  • 25
  • The above answer only explains how to detect the state of failure or success without using a Scripted Pipeline "try/catch" block. It does not explain how to set the status of the job to UNSTABLE. What should be done to set it UNSTABLE? – rgulia Jun 18 '18 at 15:33
  • 1
    set currentBuild.result = 'UNSTABLE'. More details here https://support.cloudbees.com/hc/en-us/articles/218554077-How-to-set-current-build-result-in-Pipeline – CGS Jun 20 '18 at 05:03