Skip to content

Commit

Permalink
Merge pull request #1486 from Vlatombe/container-withMaven-env
Browse files Browse the repository at this point in the history
  • Loading branch information
Vlatombe authored Dec 21, 2023
2 parents 6ab2953 + fdb014a commit 3954583
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,38 @@ 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());
r.waitForCompletion(b);
r.assertLogContains(
"from Groovy outside container: /opt/java/openjdk/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
b);
r.assertLogContains(
"from shell outside container: /opt/java/openjdk/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
b);
r.assertLogContains(
"from Groovy outside container with override: /bar:/opt/java/openjdk/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
b);
r.assertLogContains(
"from shell outside container with override: /bar:/opt/java/openjdk/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
b);
// When using groovy, the environment relies on the computer's environment.
r.assertLogContains(
"from Groovy inside container: /opt/java/openjdk/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
b);
r.assertLogContains(
"from shell inside container: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin", b);
// TODO Using groovy within container, the agent environment is used instead of the container environment.
// r.assertLogContains(
// "from Groovy inside container with override:
// /bar:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
// b);
// TODO Currently fails because env override is applied to the computer's environment instead of the container's
// environment.
// r.assertLogContains(
// "from shell inside container with override:
// /bar:/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,31 @@
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 outside container: ${env.PATH}"
sh 'echo "from shell outside container: $PATH"'
withEnv(['PATH+foo=/bar']) {
echo "from Groovy outside container with override: ${env.PATH}"
sh 'echo "from shell outside container with override: $PATH"'
}
container('alpine') {
echo "from Groovy inside container: ${env.PATH}"
sh 'echo "from shell inside container: $PATH"'
withEnv(['PATH+foo=/bar']) {
echo "from Groovy inside container with override: ${env.PATH}"
sh 'echo "from shell inside container with override: $PATH"'
}
}
}
}

0 comments on commit 3954583

Please sign in to comment.