diff --git a/pom.xml b/pom.xml index 70b8b02e2c..b4153c781a 100644 --- a/pom.xml +++ b/pom.xml @@ -203,6 +203,12 @@ junit test + + org.jenkins-ci.plugins + pipeline-maven + 1362.vee39a_d4b_02b_1 + test + org.jenkins-ci.plugins scm-api diff --git a/src/test/java/org/csanchez/jenkins/plugins/kubernetes/pipeline/ContainerExecDecoratorPipelineTest.java b/src/test/java/org/csanchez/jenkins/plugins/kubernetes/pipeline/ContainerExecDecoratorPipelineTest.java index b87d69555d..6191c90b00 100644 --- a/src/test/java/org/csanchez/jenkins/plugins/kubernetes/pipeline/ContainerExecDecoratorPipelineTest.java +++ b/src/test/java/org/csanchez/jenkins/plugins/kubernetes/pipeline/ContainerExecDecoratorPipelineTest.java @@ -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); + } } diff --git a/src/test/resources/org/csanchez/jenkins/plugins/kubernetes/pipeline/containerEnvironmentIsHonored.groovy b/src/test/resources/org/csanchez/jenkins/plugins/kubernetes/pipeline/containerEnvironmentIsHonored.groovy new file mode 100644 index 0000000000..566b8bb437 --- /dev/null +++ b/src/test/resources/org/csanchez/jenkins/plugins/kubernetes/pipeline/containerEnvironmentIsHonored.groovy @@ -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"' + } + } + } +}