Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle NOT_BUILT and ABORTED as other results
Use case -------- My use case is a post build script which does not need to fully complete. The step can be cancelled while waiting and causes the triggering build to fail. As a result I need the build step result to be passed through the BlockingBehavior so that I can set it to never block and thus be considered a SUCCESS even when NOT_BUILT or ABORTED. See: https://phabricator.wikimedia.org/T352319 Solution -------- When a triggered job is aborted (InterruptedException), the build step was throwing an AbortException which marks the parent job has having been aborted. This change catches it as an ABORTED result and passes it through the BlockingBehavior to determine the build step outcome. Jenkins Result defines ordinal ranking the results as: SUCCESS, UNSTABLE, FAILURE, NOT_BUILT, ABORTED. The NOT_BUILT and ABORTED results are thus worse than a FAILURE and would be matched as such in BlockingBehavior mapBuildStepResult() and mapBuildResult() which uses isWorseOrEqualTo() for comparison. BREAKING CHANGE: since ABORTED has a worse ordinal than FAILURE, the aborted build step causes the build to now be marked FAILURE. This is reflected in testCancelsDownstreamBuildWhenInterrupted() test which now becomes a SUCCESS (since the test blocking behavior is to never block). When a job is cancelled from the build queue (CancellationException), catch it, set the result to NOT_BUILD and pass it through the BlockingBehavior. This lets one to configure the build step to never fail or mark the build unstable when previously the exception would bubble up and call the build to fail. Add a test testCancelledFromBuildQueue() to cover the CancellationException() is caught and it results in a SUCCESS (since the test blocking behavior is to never block). ResultConditionTest covers the BlockingBehavior is able to map NOT_BUILD and ABORTED since it has two tests explicitly cancelling and interrupting jobs. Examples -------- When a build is aborted, by aborting it: Waiting for the completion of downstream-project downstream-project #7 started. downstream-project #7 completed. Result was ABORTED Build step 'Trigger/call builds on other projects' marked build as failure Finished: FAILURE When it is waiting in the build queue and cancelled: Waiting for the completion of downstream-project Not built: downstream-project has been cancelled while waiting in the queue. Build step 'Trigger/call builds on other projects' marked build as failure Finished: FAILURE
- Loading branch information