Skip to content

Commit

Permalink
Merge pull request #57 from abayer/jenkins-44379
Browse files Browse the repository at this point in the history
[FIXED JENKINS-44379] Don't retry for any FlowInterruptedException
  • Loading branch information
abayer committed Jan 19, 2018
2 parents ac2c854 + bc294db commit fa21a7c
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 6 deletions.
6 changes: 6 additions & 0 deletions pom.xml
Expand Up @@ -188,5 +188,11 @@
<version>0.5.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>pipeline-input-step</artifactId>
<version>2.8</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Expand Up @@ -57,12 +57,8 @@ public void onSuccess(StepContext context, Object result) {
public void onFailure(StepContext context, Throwable t) {
try {
if (t instanceof FlowInterruptedException) {
for (CauseOfInterruption cause : ((FlowInterruptedException) t).getCauses()) {
if (cause instanceof CauseOfInterruption.UserInterruption) {
context.onFailure(t);
return;
}
}
context.onFailure(t);
return;
}
left--;
if (left>0) {
Expand Down
@@ -1,12 +1,16 @@
package org.jenkinsci.plugins.workflow.steps;

import com.gargoylesoftware.htmlunit.html.HtmlPage;
import hudson.model.Result;
import hudson.model.User;
import hudson.model.queue.QueueTaskFuture;
import hudson.security.ACL;
import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition;
import org.jenkinsci.plugins.workflow.cps.CpsFlowExecution;
import org.jenkinsci.plugins.workflow.job.WorkflowJob;
import org.jenkinsci.plugins.workflow.job.WorkflowRun;
import org.jenkinsci.plugins.workflow.support.steps.input.InputAction;
import org.jenkinsci.plugins.workflow.support.steps.input.InputStepExecution;
import org.jenkinsci.plugins.workflow.test.steps.SemaphoreStep;
import org.junit.ClassRule;
import org.junit.Rule;
Expand Down Expand Up @@ -101,4 +105,37 @@ public void abortShouldNotRetry() throws Exception {

}

@Issue("JENKINS-44379")
@Test
public void inputAbortShouldNotRetry() throws Exception {
WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p");
p.setDefinition(new CpsFlowDefinition("int count = 0\n" +
"retry(3) {\n" +
" echo 'trying '+(count++)\n" +
" input id: 'InputX', message: 'OK?', ok: 'Yes'\n" +
"}\n", true));

QueueTaskFuture<WorkflowRun> queueTaskFuture = p.scheduleBuild2(0);
WorkflowRun run = queueTaskFuture.getStartCondition().get();
CpsFlowExecution execution = (CpsFlowExecution) run.getExecutionPromise().get();

while (run.getAction(InputAction.class) == null) {
execution.waitForSuspension();
}

InputAction inputAction = run.getAction(InputAction.class);
InputStepExecution is = inputAction.getExecution("InputX");
HtmlPage page = r.createWebClient().getPage(run, inputAction.getUrlName());

r.submit(page.getFormByName(is.getId()), "abort");
assertEquals(0, inputAction.getExecutions().size());
queueTaskFuture.get();

r.assertBuildStatus(Result.ABORTED, r.waitForCompletion(run));

r.assertLogContains("trying 0", run);
r.assertLogNotContains("trying 1", run);
r.assertLogNotContains("trying 2", run);
}

}

0 comments on commit fa21a7c

Please sign in to comment.