run.setResult(Result.FAILURE) is not failing the build

21 views
Skip to first unread message

shih...@gmail.com

unread,
Apr 30, 2021, 3:31:25 AM4/30/21
to Jenkins Developers
Hi All,

I have a Pipeline(Recorder) class and in the perform method I am setting the run.setResult(Result.FAILURE) if any exceptions are encountered. This does not fail the Pipeline job instantly but it executes the next stage in the job. Am I missing anything here? Appreciate your thoughts on this. 

Thank you.

Jesse Glick

unread,
Apr 30, 2021, 9:34:50 AM4/30/21
to Jenkins Dev
On Fri, Apr 30, 2021 at 3:31 AM shih...@gmail.com <shih...@gmail.com> wrote:
in the perform method I am setting the run.setResult(Result.FAILURE) […] This does not fail the Pipeline job instantly but it executes the next stage in the job.

Indeed. Do not call `setResult`. Throw an exception—`AbortException` if nothing in Jenkins is broken and this is just a routine build failure.


(The one case where `setResult` is sometimes used is with `UNSTABLE`, to explicitly proceed with the build while marking it as yellow. Even this is not generally a good idea; better to use https://javadoc.jenkins.io/plugin/workflow-api/org/jenkinsci/plugins/workflow/actions/WarningAction.html to be targeted. `JUnitResultsStepExecution` does both.)
Reply all
Reply to author
Forward
0 new messages