Skip to content
Permalink
Browse files

[JENKINS-41276] Make sure a FlowInterruptedException coming from a bu…

…ild abort is properly initialized with causes.
  • Loading branch information
jglick committed Feb 6, 2017
1 parent 139ac7e commit 0eeee8d0d482f08149530a337a5500b760abd9dc
@@ -28,7 +28,7 @@
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>2.19</version>
<version>2.21</version>
<relativePath />
</parent>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
@@ -66,6 +66,11 @@
<no-test-jar>false</no-test-jar>
</properties>
<dependencies>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-step-api</artifactId>
<version>2.9-20170206.170109-1</version> <!-- TODO https://github.com/jenkinsci/workflow-step-api-plugin/pull/20 -->
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-support</artifactId>
@@ -67,6 +67,7 @@
import java.io.PrintStream;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.LinkedHashMap;
@@ -86,6 +87,7 @@
import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
import javax.annotation.concurrent.GuardedBy;
import jenkins.model.CauseOfInterruption;
import jenkins.model.Jenkins;
import jenkins.model.lazy.BuildReference;
import jenkins.model.lazy.LazyBuildMixIn;
@@ -270,7 +272,8 @@ private AsynchronousExecution sleep() {
}
Executor executor = getExecutor();
try {
execution.interrupt(executor.abortResult());
Collection<CauseOfInterruption> causes = executor.getCausesOfInterruption();
execution.interrupt(executor.abortResult(), causes.toArray(new CauseOfInterruption[causes.size()]));
} catch (Exception x) {
LOGGER.log(Level.WARNING, null, x);
}
@@ -47,6 +47,7 @@
import jenkins.model.InterruptedBuildAction;
import jenkins.model.Jenkins;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;
import org.jenkinsci.plugins.scriptsecurity.scripts.ScriptApproval;
import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition;
import org.jenkinsci.plugins.workflow.cps.CpsFlowExecution;
@@ -276,6 +277,29 @@ public void failedToStartRun() throws Exception {
assertEquals(Collections.emptyList(), iba.getCauses());
}

@Issue("JENKINS-41276")
@Test public void interruptCause() throws Exception {
r.jenkins.setSecurityRealm(r.createDummySecurityRealm());
WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p");
ScriptApproval.get().approveSignature("method org.jenkinsci.plugins.workflow.steps.FlowInterruptedException getCauses"); // TODO should probably be @Whitelisted
ScriptApproval.get().approveSignature("method jenkins.model.CauseOfInterruption$UserInterruption getUser"); // ditto
p.setDefinition(new CpsFlowDefinition("@NonCPS def users(e) {e.causes*.user}; try {semaphore 'wait'} catch (e) {echo(/users=${users(e)}/); throw e}", true));
final WorkflowRun b1 = p.scheduleBuild2(0).waitForStart();
SemaphoreStep.waitForStart("wait/1", b1);
ACL.impersonate(User.get("dev").impersonate(), new Runnable() {
@Override public void run() {
b1.getExecutor().doStop();
}
});
r.assertBuildStatus(Result.ABORTED, r.waitForCompletion(b1));
r.assertLogContains("users=[dev]", b1);
InterruptedBuildAction iba = b1.getAction(InterruptedBuildAction.class);
assertNotNull(iba);
assertEquals(Collections.singletonList(new CauseOfInterruption.UserInterruption("dev")), iba.getCauses());
String log = JenkinsRule.getLog(b1);
assertEquals(log, 1, StringUtils.countMatches(log, jenkins.model.Messages.CauseOfInterruption_ShortDescription("dev")));
}

@Test
@Issue({"JENKINS-26122", "JENKINS-28222"})
public void parallelBranchLabels() throws Exception {

0 comments on commit 0eeee8d

Please sign in to comment.