Skip to content
Permalink
Browse files

[JENKINS-41276] Merging #36 incl. workflow-step-api 2.9

  • Loading branch information
jglick committed Feb 8, 2017
2 parents 139ac7e + 0b75875 commit 00d7e14f4613fa45d2280c246808ee477b74515e
@@ -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</version>
</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;
@@ -272,8 +273,30 @@ public void failedToStartRun() throws Exception {
ex.interrupt();
r.assertBuildStatus(Result.ABORTED, r.waitForCompletion(b2));
iba = b2.getAction(InterruptedBuildAction.class);
assertNull(iba);
}

@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.emptyList(), iba.getCauses());
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

0 comments on commit 00d7e14

Please sign in to comment.