Skip to content

Commit bc361ab

Browse files
committed
Merge branch 'master' into Jenkinsfile
2 parents 752e819 + 95b9dd1 commit bc361ab

File tree

5 files changed

+67
-4
lines changed

5 files changed

+67
-4
lines changed

pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
</parent>
3434
<groupId>org.jenkins-ci.plugins.workflow</groupId>
3535
<artifactId>workflow-durable-task-step</artifactId>
36-
<version>2.10-SNAPSHOT</version>
36+
<version>2.11-SNAPSHOT</version>
3737
<packaging>hpi</packaging>
3838
<name>Pipeline: Nodes and Processes</name>
3939
<url>https://wiki.jenkins-ci.org/display/JENKINS/Pipeline+Nodes+and+Processes+Plugin</url>

src/main/java/org/jenkinsci/plugins/workflow/steps/durable_task/DurableTaskStep.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -205,10 +205,9 @@ static final class Execution extends AbstractStepExecutionImpl implements Runnab
205205
l = new LogTaskListener(LOGGER, Level.FINE);
206206
}
207207
} catch (Exception x) {
208-
LOGGER.log(Level.WARNING, "JENKINS-34021: could not get TaskListener in " + context, x);
208+
LOGGER.log(Level.FINE, "JENKINS-34021: could not get TaskListener in " + context, x);
209209
l = new LogTaskListener(LOGGER, Level.FINE);
210210
recurrencePeriod = 0;
211-
getContext().onFailure(x);
212211
}
213212
return l.getLogger();
214213
}

src/main/java/org/jenkinsci/plugins/workflow/support/steps/ExecutorStepExecution.java

+8-1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@
4848
import jenkins.util.Timer;
4949
import org.acegisecurity.AccessDeniedException;
5050
import org.acegisecurity.Authentication;
51+
import org.acegisecurity.context.SecurityContext;
52+
import org.acegisecurity.context.SecurityContextHolder;
5153
import org.jenkinsci.plugins.durabletask.executors.ContinuableExecutable;
5254
import org.jenkinsci.plugins.durabletask.executors.ContinuedTask;
5355
import org.jenkinsci.plugins.workflow.flow.FlowExecution;
@@ -383,7 +385,12 @@ private Object readResolve() {
383385
public @CheckForNull Run<?,?> runForDisplay() {
384386
Run<?,?> r = run();
385387
if (r == null && /* not stored prior to 1.13 */runId != null) {
386-
return Run.fromExternalizableId(runId);
388+
SecurityContext orig = ACL.impersonate(ACL.SYSTEM);
389+
try {
390+
return Run.fromExternalizableId(runId);
391+
} finally {
392+
SecurityContextHolder.setContext(orig);
393+
}
387394
}
388395
return r;
389396
}

src/test/java/org/jenkinsci/plugins/workflow/steps/durable_task/ShellStepTest.java

+21
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,11 @@
1414
import hudson.tasks.Shell;
1515
import java.io.File;
1616
import java.io.Serializable;
17+
import java.util.logging.Level;
18+
import java.util.logging.LogRecord;
1719
import static org.hamcrest.Matchers.containsString;
1820
import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition;
21+
import org.jenkinsci.plugins.workflow.cps.CpsStepContext;
1922
import org.jenkinsci.plugins.workflow.cps.nodes.StepAtomNode;
2023
import org.jenkinsci.plugins.workflow.job.WorkflowJob;
2124
import org.jenkinsci.plugins.workflow.job.WorkflowRun;
@@ -35,6 +38,7 @@
3538
import org.jvnet.hudson.test.BuildWatcher;
3639
import org.jvnet.hudson.test.Issue;
3740
import org.jvnet.hudson.test.JenkinsRule;
41+
import org.jvnet.hudson.test.LoggerRule;
3842
import org.jvnet.hudson.test.TestExtension;
3943
import org.kohsuke.stapler.DataBoundConstructor;
4044

@@ -45,6 +49,8 @@ public class ShellStepTest {
4549

4650
@Rule public JenkinsRule j = new JenkinsRule();
4751

52+
@Rule public LoggerRule logging = new LoggerRule();
53+
4854
/**
4955
* Failure in the shell script should mark the step as red
5056
*/
@@ -224,6 +230,21 @@ public DescriptorImpl() {
224230
j.assertLogContains("truth is 0 but falsity is 1", j.assertBuildStatusSuccess(p.scheduleBuild2(0)));
225231
}
226232

233+
@Issue("JENKINS-34021")
234+
@Test public void deadStep() throws Exception {
235+
logging.record(DurableTaskStep.class, Level.INFO).record(CpsStepContext.class, Level.INFO).capture(100);
236+
WorkflowJob p = j.jenkins.createProject(WorkflowJob.class, "p");
237+
p.setDefinition(new CpsFlowDefinition("try {node {isUnix() ? sh('sleep infinity') : bat('ping 127.0.0.1 > nul')}} catch (e) {sleep 1; throw e}", true));
238+
WorkflowRun b = p.scheduleBuild2(0).waitForStart();
239+
j.waitForMessage(Functions.isWindows() ? ">ping" : "+ sleep", b);
240+
b.doTerm();
241+
j.waitForCompletion(b);
242+
j.assertBuildStatus(Result.ABORTED, b);
243+
for (LogRecord record : logging.getRecords()) {
244+
assertNull(record.getThrown());
245+
}
246+
}
247+
227248
/**
228249
* Asserts that the predicate remains true up to the given timeout.
229250
*/

src/test/java/org/jenkinsci/plugins/workflow/support/pickles/ExecutorPickleTest.java

+36
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,13 @@
2424

2525
package org.jenkinsci.plugins.workflow.support.pickles;
2626

27+
import hudson.model.Item;
2728
import hudson.model.Label;
2829
import hudson.model.Queue;
30+
import hudson.model.User;
2931
import hudson.slaves.DumbSlave;
32+
import hudson.slaves.OfflineCause;
33+
import jenkins.model.Jenkins;
3034
import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition;
3135
import org.jenkinsci.plugins.workflow.job.WorkflowJob;
3236
import org.jenkinsci.plugins.workflow.job.WorkflowRun;
@@ -38,12 +42,15 @@
3842
import org.junit.Rule;
3943
import org.junit.runners.model.Statement;
4044
import org.jvnet.hudson.test.BuildWatcher;
45+
import org.jvnet.hudson.test.Issue;
46+
import org.jvnet.hudson.test.MockAuthorizationStrategy;
4147
import org.jvnet.hudson.test.RestartableJenkinsRule;
4248

4349
public class ExecutorPickleTest {
4450

4551
@ClassRule public static BuildWatcher buildWatcher = new BuildWatcher();
4652
@Rule public RestartableJenkinsRule r = new RestartableJenkinsRule();
53+
//@Rule public LoggerRule logging = new LoggerRule().record(Queue.class, Level.FINE);
4754

4855
@Test public void canceledQueueItem() throws Exception {
4956
r.addStep(new Statement() {
@@ -71,4 +78,33 @@ public class ExecutorPickleTest {
7178
});
7279
}
7380

81+
@Issue("JENKINS-42556")
82+
@Test public void anonDiscover() {
83+
r.addStep(new Statement() {
84+
@Override public void evaluate() throws Throwable {
85+
r.j.jenkins.setSecurityRealm(r.j.createDummySecurityRealm());
86+
r.j.jenkins.setAuthorizationStrategy(new MockAuthorizationStrategy().
87+
grant(Jenkins.ADMINISTER).everywhere().to("admin").
88+
grant(Jenkins.READ, Item.DISCOVER).everywhere().toEveryone());
89+
r.j.jenkins.save(); // TODO pending https://github.com/jenkinsci/jenkins/pull/2790
90+
DumbSlave remote = r.j.createSlave("remote", null, null);
91+
WorkflowJob p = r.j.createProject(WorkflowJob.class, "p");
92+
p.setDefinition(new CpsFlowDefinition("node('remote') {semaphore 'wait'}", true));
93+
SemaphoreStep.waitForStart("wait/1", p.scheduleBuild2(0).waitForStart());
94+
remote.toComputer().setTemporarilyOffline(true, new OfflineCause.UserCause(User.get("admin"), "hold"));
95+
}
96+
});
97+
r.addStep(new Statement() {
98+
@Override public void evaluate() throws Throwable {
99+
SemaphoreStep.success("wait/1", null);
100+
WorkflowJob p = r.j.jenkins.getItemByFullName("p", WorkflowJob.class);
101+
assertFalse(p.getACL().hasPermission(Jenkins.ANONYMOUS, Item.READ));
102+
WorkflowRun b = p.getBuildByNumber(1);
103+
r.j.waitForMessage(Messages.ExecutorPickle_waiting_to_resume(Messages.ExecutorStepExecution_PlaceholderTask_displayName(b.getFullDisplayName())), b);
104+
r.j.jenkins.getNode("remote").toComputer().setTemporarilyOffline(false, null);
105+
r.j.assertBuildStatusSuccess(r.j.waitForCompletion(b));
106+
}
107+
});
108+
}
109+
74110
}

0 commit comments

Comments
 (0)