Skip to content

Commit

Permalink
Checking that environment is the one we expect inside container() step
Browse files Browse the repository at this point in the history
  • Loading branch information
Vlatombe committed Dec 20, 2023
1 parent de0cff4 commit 17ef480
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,12 @@
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>pipeline-maven</artifactId>
<version>1362.vee39a_d4b_02b_1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>scm-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,16 @@ public void envVarDollarSignEscaping() throws Exception {
r.assertLogContains("outside container: $string$with$dollars", b);
r.assertLogContains("inside container: $string$with$dollars", b);
}

@Test
public void containerEnvironmentIsHonored() throws Exception {
assertNotNull(createJobThenScheduleRun());
containerExecLogs.capture(1000);
r.waitForCompletion(b);
r.assertLogContains(
"from Groovy: /opt/java/openjdk/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin", b);
r.assertLogContains("inside container: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin", b);
r.assertLogContains(
"inside withMaven in container: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin", b);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
podTemplate(yaml: '''
spec:
containers:
- name: jnlp
image: jenkins/inbound-agent:3192.v713e3b_039fb_e-1
# PATH=/opt/java/openjdk/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
- name: alpine
image: alpine:3.19.0
# PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
command:
- sleep
args:
- infinity
''') {
node(POD_LABEL) {
echo "from Groovy: ${env.PATH}"
sh 'echo "outside container: $PATH"'
container('alpine') {
sh 'echo "inside container: $PATH"'
withMaven(publisherStrategy: 'EXPLICIT', traceability: false) {
sh 'echo "inside withMaven in container: $PATH"'
}
}
}
}

0 comments on commit 17ef480

Please sign in to comment.