Skip to content

Commit

Permalink
[FIXED JENKINS-50652] Don't fire post failure for aborted durable task
Browse files Browse the repository at this point in the history
It appears that an aborted durable task like sh results in
`CpsFlowExecution#result` being `ABORTED`, but `WorkflowRun#result`
being `FAILURE`, until the whole build actually finishes and the run
gets updated accordingly. So the `failure` `post` condition shouldn't
fire if `CpsFlowExecution#result` is `ABORTED`.
  • Loading branch information
abayer committed Apr 11, 2018
1 parent 6d3b9dc commit 70d2af8
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
Expand Up @@ -41,7 +41,8 @@ class Failure extends BuildCondition {
@Override
boolean meetsCondition(@Nonnull WorkflowRun r) {
Result execResult = getExecutionResult(r)
return execResult == Result.FAILURE || r.getResult() == Result.FAILURE
return execResult != Result.ABORTED &&
(execResult == Result.FAILURE || r.getResult() == Result.FAILURE)
}

@Override
Expand Down
Expand Up @@ -242,4 +242,44 @@ public void changedAndNotSuccess() throws Exception {
j.assertLogNotContains("I FAILED", b3);
}

@Issue("JENKINS-50652")
@Test
public void abortedShouldNotTriggerFailure() throws Exception {
onAllowedOS(PossibleOS.LINUX, PossibleOS.MAC);
WorkflowJob job = j.jenkins.createProject(WorkflowJob.class, "abort");
job.setDefinition(new CpsFlowDefinition("" +
"pipeline {\n" +
" agent any\n" +
" stages {\n" +
" stage('foo') {\n" +
" steps {\n" +
" echo 'hello'\n" +
" semaphore 'wait'\n" +
" sh 'sleep 15'\n" +
" }\n" +
" }\n" +
" }\n" +
" post {\n" +
" aborted {\n" +
" echo 'I AM ABORTED'\n" +
" }\n" +
" failure {\n" +
" echo 'I FAILED'\n" +
" }\n" +
" }\n" +
"}\n", true));

WorkflowRun run1 = job.scheduleBuild2(0).waitForStart();
SemaphoreStep.waitForStart("wait/1", run1);
SemaphoreStep.success("wait/1", null);
Thread.sleep(1000);
run1.doStop();

j.assertBuildStatus(Result.ABORTED, j.waitForCompletion(run1));

j.assertLogContains("I AM ABORTED", run1);

j.assertLogNotContains("I FAILED", run1);

}
}

0 comments on commit 70d2af8

Please sign in to comment.