Skip to content

Commit 5c8b27a

Browse files
authored
Merge pull request #364 from abayer/jenkins-52623
[FIXED JENKINS-52623] Use Declarative's CheckoutScript to populate env
2 parents 756032a + ea6ba0e commit 5c8b27a

File tree

3 files changed

+50
-36
lines changed

3 files changed

+50
-36
lines changed

pom.xml

+26-16
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484
<dependency> <!-- Requires Permission -->
8585
<groupId>org.jenkins-ci.plugins</groupId>
8686
<artifactId>cloudbees-folder</artifactId>
87-
<version>5.12</version>
87+
<version>5.18</version>
8888
</dependency>
8989

9090
<dependency> <!-- OnceRetentionStrategy -->
@@ -100,26 +100,26 @@
100100
<dependency>
101101
<groupId>org.jenkins-ci.plugins.workflow</groupId>
102102
<artifactId>workflow-step-api</artifactId>
103-
<version>2.11</version>
103+
<version>2.14</version>
104104
</dependency>
105105
<dependency> <!-- DeclarativeAgent -->
106106
<groupId>org.jenkinsci.plugins</groupId>
107107
<artifactId>pipeline-model-extensions</artifactId>
108-
<version>1.1.2</version>
108+
<version>1.3.1</version>
109109
<optional>true</optional>
110110
</dependency>
111111

112112
<!-- for testing -->
113113
<dependency>
114114
<groupId>org.jenkins-ci.plugins.workflow</groupId>
115115
<artifactId>workflow-job</artifactId>
116-
<version>2.9</version>
116+
<version>2.15</version>
117117
<scope>test</scope>
118118
</dependency>
119119
<dependency>
120120
<groupId>org.jenkins-ci.plugins.workflow</groupId>
121121
<artifactId>workflow-basic-steps</artifactId>
122-
<version>2.3</version>
122+
<version>2.6</version>
123123
<scope>test</scope>
124124
</dependency>
125125
<dependency> <!-- StepConfigTester -->
@@ -132,26 +132,26 @@
132132
<dependency>
133133
<groupId>org.jenkins-ci.plugins.workflow</groupId>
134134
<artifactId>workflow-support</artifactId>
135-
<version>2.14</version>
135+
<version>2.17</version>
136136
<scope>test</scope>
137137
</dependency>
138138
<dependency>
139139
<groupId>org.jenkins-ci.plugins.workflow</groupId>
140140
<artifactId>workflow-durable-task-step</artifactId>
141-
<version>2.11</version>
141+
<version>2.15</version>
142142
<scope>test</scope>
143143
</dependency>
144144
<dependency> <!-- SemaphoreStep -->
145145
<groupId>org.jenkins-ci.plugins.workflow</groupId>
146146
<artifactId>workflow-support</artifactId>
147-
<version>2.14</version>
147+
<version>2.17</version>
148148
<classifier>tests</classifier>
149149
<scope>test</scope>
150150
</dependency>
151151
<dependency>
152152
<groupId>org.jenkins-ci.plugins.workflow</groupId>
153153
<artifactId>workflow-scm-step</artifactId>
154-
<version>2.4</version>
154+
<version>2.6</version>
155155
<scope>test</scope>
156156
</dependency>
157157
<dependency>
@@ -163,19 +163,19 @@
163163
<dependency>
164164
<groupId>org.jenkinsci.plugins</groupId>
165165
<artifactId>pipeline-model-definition</artifactId>
166-
<version>1.1.2</version>
166+
<version>1.3.1</version>
167167
<scope>test</scope>
168168
</dependency>
169169
<dependency>
170170
<groupId>org.jenkins-ci.plugins.workflow</groupId>
171171
<artifactId>workflow-api</artifactId>
172-
<version>2.11</version>
172+
<version>2.25</version>
173173
<scope>test</scope>
174174
</dependency>
175175
<dependency>
176176
<groupId>org.jenkins-ci.plugins.workflow</groupId>
177177
<artifactId>workflow-cps</artifactId>
178-
<version>2.29</version>
178+
<version>2.46</version>
179179
<scope>test</scope>
180180
</dependency>
181181
<dependency>
@@ -238,19 +238,29 @@
238238
<dependency>
239239
<groupId>org.jenkins-ci.plugins</groupId>
240240
<artifactId>credentials</artifactId>
241-
<version>2.1.14</version>
241+
<version>2.1.16</version>
242242
</dependency>
243243

244244
<!-- just to fix enforcer RequireUpperBoundDeps -->
245+
<dependency>
246+
<groupId>org.jenkins-ci.plugins</groupId>
247+
<artifactId>script-security</artifactId>
248+
<version>1.42</version>
249+
</dependency>
250+
<dependency>
251+
<groupId>org.jenkins-ci.plugins</groupId>
252+
<artifactId>git-client</artifactId>
253+
<version>2.7.0</version>
254+
</dependency>
245255
<dependency>
246256
<groupId>org.jenkins-ci.plugins</groupId>
247257
<artifactId>credentials-binding</artifactId>
248-
<version>1.12</version>
258+
<version>1.14</version>
249259
</dependency>
250260
<dependency>
251261
<groupId>org.jenkins-ci.plugins</groupId>
252262
<artifactId>structs</artifactId>
253-
<version>1.10</version>
263+
<version>1.14</version>
254264
</dependency>
255265
<dependency>
256266
<groupId>org.jenkins-ci.plugins</groupId>
@@ -270,7 +280,7 @@
270280
<dependency>
271281
<groupId>org.jenkins-ci.plugins</groupId>
272282
<artifactId>mailer</artifactId>
273-
<version>1.18</version>
283+
<version>1.20</version>
274284
</dependency>
275285
<dependency>
276286
<groupId>org.jenkins-ci.plugins</groupId>

src/main/resources/org/csanchez/jenkins/plugins/kubernetes/pipeline/KubernetesDeclarativeAgentScript.groovy

+13-20
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ package org.csanchez.jenkins.plugins.kubernetes.pipeline
2525

2626
import hudson.model.Result
2727
import org.jenkinsci.plugins.pipeline.modeldefinition.SyntheticStageNames
28+
import org.jenkinsci.plugins.pipeline.modeldefinition.agent.CheckoutScript
2829
import org.jenkinsci.plugins.pipeline.modeldefinition.agent.DeclarativeAgentScript
2930
import org.jenkinsci.plugins.workflow.cps.CpsScript
3031

@@ -44,28 +45,20 @@ public class KubernetesDeclarativeAgentScript extends DeclarativeAgentScript<Kub
4445
}
4546
script.podTemplate(describable.asArgs) {
4647
script.node(describable.label) {
47-
if (describable.isDoCheckout() && describable.hasScmContext(script)) {
48-
if (!describable.inStage) {
49-
script.stage(SyntheticStageNames.checkout()) {
50-
script.checkout script.scm
51-
}
52-
} else {
53-
// No stage when we're in a nested stage already
54-
script.checkout script.scm
55-
}
56-
}
57-
// what container to use for the main body
58-
def container = describable.defaultContainer ?: 'jnlp';
48+
CheckoutScript.doCheckout(script, describable) {
49+
// what container to use for the main body
50+
def container = describable.defaultContainer ?: 'jnlp';
5951

60-
if (describable.containerTemplate != null) {
61-
// run inside the container declared for backwards compatibility
62-
container = describable.containerTemplate.asArgs;
63-
}
52+
if (describable.containerTemplate != null) {
53+
// run inside the container declared for backwards compatibility
54+
container = describable.containerTemplate.asArgs;
55+
}
6456

65-
// call the main body
66-
script.container(container) {
67-
body.call()
68-
}
57+
// call the main body
58+
script.container(container) {
59+
body.call()
60+
}
61+
}.call()
6962
}
7063
}
7164
} catch (Exception e) {

src/test/java/org/csanchez/jenkins/plugins/kubernetes/pipeline/KubernetesDeclarativeAgentTest.java

+11
Original file line numberDiff line numberDiff line change
@@ -87,4 +87,15 @@ public void declarativeFromYamlFile() throws Exception {
8787
r.assertLogContains("MAVEN_CONTAINER_ENV_VAR = maven\n", b);
8888
r.assertLogContains("BUSYBOX_CONTAINER_ENV_VAR = busybox\n", b);
8989
}
90+
91+
@Issue("JENKINS-52623")
92+
@Test
93+
public void declarativeSCMVars() throws Exception {
94+
WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "job with repo");
95+
// We can't use a local GitSampleRepoRule for this because the repo has to be accessible from within the container.
96+
p.setDefinition(new CpsScmFlowDefinition(new GitStep("https://github.com/abayer/jenkins-52623.git").createSCM(), "Jenkinsfile"));
97+
WorkflowRun b = r.buildAndAssertSuccess(p);
98+
r.assertLogContains("Outside container: GIT_BRANCH is origin/master", b);
99+
r.assertLogContains("In container: GIT_BRANCH is origin/master", b);
100+
}
90101
}

0 commit comments

Comments
 (0)