Search code examples
jenkinsjenkins-pipelinepipelinestatus

Cannot Set the Job status back to Success in Jenkins Pipeline


I'm using the env variable "currentBuild.result" to modify the overall job status of a Jenkins job.
I can set it to a failure using

currentBuild.result = 'FAILURE'

and I can set it to Aborted using

currentBuild.result = 'ABORTED'

but I cannot clear these back to success using

currentBuild.result = 'SUCCESS'

This is driving me nuts, Any idea what I'm doing wrong here and any pointers on how to set the overall job status to Success after they have been set to some other state?

Appreciate any pointers in advance!


Solution

  • This can be done using the rawBuild state.

    import hudson.model.Result
    currentBuild.rawBuild.@result = hudson.model.Result.SUCCESS
    

    Found the answer from this question. How to manipulate the build result of a Jenkins pipeline job?