How do I upgrade currentBuild.result to 'FAILURE' in case currentBuild.result == 'UNSTABLE'?

Hi all!

I am using a Jenkins pipeline to run several long duration simulations. In case there is a compilation error or warning, the simulators exit with 1 or -1, due to which the Jenkins build status will be set to FAILURE. I use JUnit to find issues post-simulation in the simulation logs. In case failure patterns are detected in the .xml outputs, the build status will be set to UNSTABLE.

Other parts of the testing pipeline require currentBuild.result to be FAILURE in the latter case as well however. Is there a way to upgrade the UNSTABLE status to FAILURE via “always” as the last step of every pipeline?

If this isn’t possible in the Jenkins YAML, is it possible via some workaround? Or should I modify my scripts in a way that they can predict an UNSTABLE state and exit with 1 or -1?

Appreciate the help in advance!

Extra context:

  1. Project language: SystemVerilog/UVM
  2. Scripting: tcsh/Python
  3. Jenkins runs tcsh script that starts all simulations.
  4. I’m a complete Jenkins noob, I’m happy I even got the script set up.
  5. I looked online, and all information I found was regarding changing UNSTABLE to SUCCESS, which is categorically impossible. However as far as I know downgrading the result to FAILURE is possible, I just couldn’t find any info on whether there is an easy way to do it or not.

You can use catchError with post il you want to continue
buildResult status you would detect
stageResult status you set to stage

stage(“if fail y continue”) {
steps {
script {
catchError(buildResult: ‘FAILURE’, stageResult: ‘FAILURE’) {
your work
}
}
}
post {
failure {
echo ‘One way or another, I have finished’
sh ‘exit 0’
}
}
}