Once you are out of a stage you can't change the stage status AFAIK. The better option is to refactor your Pipeline to something like below. Basically, run your stages in parallel.
```groovy
pipeline {
agent any
stages {
stage('Parallel Example') {
parallel {
stage('1') {
steps {
build_job_result = build job: "jobName", wait: true
if (build_job_result == failed) {
error "Build Failed"
}
}
}
stage('2') {
steps {
echo 'Do something else while the job runs'
}
}
}
}
}
}
```
I did it like this (to keep the catchError):
def boolean test_results = false
pipeline {
...
stage( 'x' ) {
steps{
catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE') {
<Do some dangerous stuff here>
//
// If we reached here the above step hasn't failed
//
script { test_results = true }
}
}
}
stage( 'y' ) {
steps{
script{
if( test_results == true ) {
} else {
}
}
}
}
}