-
Bug
-
Resolution: Unresolved
-
Minor
-
None
Issue
When overriding the jnlp container workingDir, every other container's workingDir is overridden with the same value. This seems inconsistent.
How to reproduce
Build an image from a Dockerfile like the following:
{{}}
FROM python:3.7-slim WORKDIR /home CMD [ "/bin/bash" , "-c" , "pwd > /home/show-the-working-dir.txt && sleep 1200" ]
Scenario 1: Issue with custom JNLP workingDir
Run the following pipeline:
{{}}
pipeline { agent { kubernetes { yaml """ apiVersion: v1 kind: Pod spec: containers: - name: jnlp workingDir: "/home/jenkins" - name: python image: dohbedoh/test-python-jenkins:0.0.1 tty: true """ } } stages { stage('Test') { steps { script { container('python') { sh """|#!/bin/bash |set -euox pipefail |cat /home/show-the-working-dir.txt |""".stripMargin() } } } } } }
Expected output:
{{}}
+ cat /home/show-the-working-dir.txt /home
{{}}
{{Actual output: }}
{{}}
+ cat /home/show-the-working-dir.txt /home/jenkins/agent
{{}}
Scenario 2: Behavior without custom JNLP workingDir
Run the following pipeline:
{{}}
pipeline { agent { kubernetes { yaml """ apiVersion: v1 kind: Pod spec: containers: - name: python image: dohbedoh/test-python-jenkins:0.0.1 tty: true """ } } stages { stage('Test') { steps { script { container('python') { sh """|#!/bin/bash |set -euox pipefail |cat /home/show-the-working-dir.txt |""".stripMargin() } } } } } }
Expected output = Actual output:
{{}}
+ cat /home/show-the-working-dir.txt /home
Workaround
Set the workingDir explicitly to every container definition.
Further Note
The workingDir needed to be aligned (see https://github.com/jenkinsci/kubernetes-plugin/blob/kubernetes-1.25.7/src/main/java/org/csanchez/jenkins/plugins/kubernetes/PodTemplateBuilder.java#L247). But since the improvement JENKINS-58975 (shipped in version 1.22.1) this constraint might not be needed anymore.