Skip to content

Commit d705fc7

Browse files
authored
Merge pull request #968 from Vlatombe/replayflowfactoryaction-sandbox-persistent
Persist `ReplayFlowFactoryAction#sandbox`
2 parents f9c5614 + 442b2cb commit d705fc7

File tree

2 files changed

+94
-1
lines changed

2 files changed

+94
-1
lines changed

plugin/src/main/java/org/jenkinsci/plugins/workflow/cps/replay/ReplayFlowFactoryAction.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class ReplayFlowFactoryAction extends InvisibleAction implements CpsFlowFactoryA
5252

5353
private String replacementMainScript;
5454
private final Map<String,String> replacementLoadedScripts;
55-
private transient final boolean sandbox;
55+
private final boolean sandbox;
5656

5757
ReplayFlowFactoryAction(@NonNull String replacementMainScript, @NonNull Map<String,String> replacementLoadedScripts, boolean sandbox) {
5858
this.replacementMainScript = replacementMainScript;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/*
2+
* The MIT License
3+
*
4+
* Copyright (c) 2013-2014, CloudBees, Inc.
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
* THE SOFTWARE.
23+
*/
24+
25+
package org.jenkinsci.plugins.workflow;
26+
27+
import static org.awaitility.Awaitility.await;
28+
import static org.hamcrest.MatcherAssert.assertThat;
29+
import static org.hamcrest.Matchers.is;
30+
import static org.junit.Assert.assertNotNull;
31+
import static org.junit.Assert.assertTrue;
32+
33+
import java.util.HashMap;
34+
import org.hamcrest.Matchers;
35+
import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition;
36+
import org.jenkinsci.plugins.workflow.cps.CpsFlowExecution;
37+
import org.jenkinsci.plugins.workflow.cps.replay.ReplayAction;
38+
import org.jenkinsci.plugins.workflow.job.WorkflowJob;
39+
import org.jenkinsci.plugins.workflow.job.WorkflowRun;
40+
import org.jenkinsci.plugins.workflow.support.steps.input.InputAction;
41+
import org.jenkinsci.plugins.workflow.support.steps.input.InputStepExecution;
42+
import org.junit.Rule;
43+
import org.junit.Test;
44+
import org.jvnet.hudson.test.JenkinsRule;
45+
import org.jvnet.hudson.test.JenkinsSessionRule;
46+
47+
/**
48+
* Tests of pipelines that involve restarting Jenkins in the middle.
49+
*/
50+
public class Workflow2Test {
51+
@Rule
52+
public JenkinsSessionRule story = new JenkinsSessionRule();
53+
54+
@Test
55+
public void restartAReplayedBuild() throws Throwable {
56+
story.then(Workflow2Test::stage1);
57+
story.then(Workflow2Test::stage2);
58+
}
59+
60+
/**
61+
* <li>Create a project with concurrency disabled
62+
* <li>Schedule a first build, paused waiting for input.
63+
* <li>Replay it. Since the first build is still running, the replayed build is in queue.
64+
*/
65+
private static void stage1(JenkinsRule r) throws Throwable {
66+
WorkflowJob p = r.createProject(WorkflowJob.class, "demo");
67+
p.setConcurrentBuild(false);
68+
p.setDefinition(new CpsFlowDefinition("input 'Waiting for approval'", true));
69+
WorkflowRun b = p.scheduleBuild2(0).waitForStart();
70+
r.waitForMessage("Waiting for approval", b);
71+
// Start a replay
72+
b.getAction(ReplayAction.class).run("input 'Waiting for approval'", new HashMap<>());
73+
}
74+
75+
/**
76+
* After a restart
77+
* <li>unblock the first build, allowing it to complete
78+
* <li>check sandbox status for the second build
79+
*/
80+
private static void stage2(JenkinsRule r) throws Throwable {
81+
var p = r.jenkins.getItemByFullName("demo", WorkflowJob.class);
82+
var b = p.getBuildByNumber(1);
83+
InputAction inputAction = b.getAction(InputAction.class);
84+
assertNotNull(inputAction);
85+
assertTrue(inputAction.isWaitingForInput());
86+
InputStepExecution inputStepExecution = inputAction.getExecutions().get(0);
87+
assertNotNull(inputStepExecution);
88+
inputStepExecution.proceed(null);
89+
r.assertBuildStatusSuccess(r.waitForCompletion(b));
90+
var b2 = await().until(() -> p.getBuildByNumber(2), Matchers.notNullValue());
91+
assertThat("Expecting the replayed build to use sandbox", ((CpsFlowExecution) b2.getExecution()).isSandbox(), is(true));
92+
}
93+
}

0 commit comments

Comments
 (0)