-
Notifications
You must be signed in to change notification settings - Fork 175
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Handle NOT_BUILT and ABORTED as other results #400
Open
hashar
wants to merge
3
commits into
jenkinsci:master
Choose a base branch
from
hashar:handle-not_built-canceled
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
hashar
force-pushed
the
handle-not_built-canceled
branch
from
October 23, 2024 13:58
ec4350c
to
9f7e52b
Compare
hashar
force-pushed
the
handle-not_built-canceled
branch
from
November 4, 2024 15:33
9f7e52b
to
a95cb34
Compare
The commit message and the pull request text should be adjusted to take that in account. I have thus marked this as being in draft until I fix the texts. |
hashar
force-pushed
the
handle-not_built-canceled
branch
from
November 14, 2024 13:03
a95cb34
to
a455d7e
Compare
Instead of: if (condition != null) { // indented large block code } else { log.info("Skipped"); } Inverse the condition check to move the logging code at the top and add an explicit continue. This saves a level of indentation on the code block: if (condition == null) { log.info("Skipped"); continue; } // large block code Also adjust the logging message while at it: vv - The project was not trigger by some reason. + The project was not trigger for some reason. ^^^
Instead of invoking `completedRun.getResult()` several times, invoke it once and reuse the resust. That makes the code slightly easier to read.
hashar
force-pushed
the
handle-not_built-canceled
branch
from
November 14, 2024 13:04
a455d7e
to
9eaaf80
Compare
hashar
force-pushed
the
handle-not_built-canceled
branch
from
November 18, 2024 09:45
9eaaf80
to
d1e4c3a
Compare
Use case -------- My use case is a post build script triggering a job which does not need to fully complete. Since the build step can be cancelled while waiting or building, it causes the triggering build to be marked as a failure despite asking to never block. To fix that, I need the plugin to pass the result of the build step through BlockingBehaviour. That lets one define how to behave when the triggered build is NOT_BUILT (it got cancelled from the queue). In my case I need it to never block. See: https://phabricator.wikimedia.org/T352319 Solution -------- There are multiple reasons for a job to not fully complete: - it is interrupted, an InterruptedException is thrown, this is still rethrown and Jenkins will mark the build as ABORTED. - it can be cancelled from the build queue raising a CancellationException. This previously raised an AbortException which Jenkins handles by marking the build as a failure. I have changed it to a NOT_BUILT result which can be process as other results (addressing my use case to have it to never block). The Jenkins Result class ranks 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 both use isWorseOrEqualTo() for comparison. 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). The ResultConditionTest test covers that BlockingBehavior is able to map NOT_BUILD and ABORTED since it has two tests explicitly cancelling and interrupting jobs. Examples -------- When a build is ongoing and when aborting it: Waiting for the completion of downstream-project downstream-project jenkinsci#7 started. downstream-project jenkinsci#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 get 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
hashar
force-pushed
the
handle-not_built-canceled
branch
from
November 18, 2024 09:52
d1e4c3a
to
ee51c9c
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Use case
My use case is a post build script triggering a job which does not need to fully complete. Since the build step can be cancelled while waiting or building, it causes the triggering build to be marked as a failure despite asking to never block.
To fix that, I need the plugin to pass the result of the build step through
BlockingBehaviour
. That lets one define how to behave when the triggered build isNOT_BUILT
(it got cancelled frmo the queue). In my case I need it to never block.See: https://phabricator.wikimedia.org/T352319
Solution
There are multiple reasons for a job to not fully complete:
it is interrupted, an InterruptedException is thrown, this is still rethrown and Jenkins will mark the build as
ABORTED
.it can be cancelled from the build queue raising a
CancellationException
. This previously raised anAbortException
which Jenkins handles by marking the build as a failure. I have changed it to aNOT_BUILT
result which can be process as other results (addressing my use case to have it to never block).The Jenkins Result class ranks the results as:
SUCCESS
UNSTABLE
FAILURE
NOT_BUILT
ABORTED
.The
NOT_BUILT
andABORTED
results are thus worse than aFAILURE
and would be matched as such inBlockingBehavior
mapBuildStepResult()
andmapBuildResult()
which both useisWorseOrEqualTo()
for comparison.Add a test
testCancelledFromBuildQueue()
to cover theCancellationException()
is caught and it results in aSUCCESS
(since the test blocking behavior is to never block).The
ResultConditionTest
test covers thatBlockingBehavior
is able to mapNOT_BUILD
andABORTED
since it has two tests explicitly cancelling and interrupting jobs.Examples
When a build is ongoing and when aborting it:
When it is waiting in the build queue and get cancelled:
Testing done
I have created two jobs in a Jenkins spinned up with
mvn hpi:run
. I have covered the behavior for cancelled jobs with a new testTriggerBuilderTest.testCancelledFromBuildQueue()
.The result mapping for
ABORTED
andNOT_BUILD
is already covered byResultConditionTest
.Submitter checklist
handle-not_built-canceled