<p>I have a simple Jenkins pipeline which creates a pod with 3 containers - jnlp, dind, example-test</p>
<p>This looks as follows -</p>
<pre class="lang-yaml prettyprint-override"><code>    agent {
        kubernetes {
      yaml &quot;&quot;&quot;
apiVersion: v1
kind: Pod
metadata:
  name: example-pb
  annotations:
    container.apparmor.security.beta.kubernetes.io/dind: unconfined
    container.seccomp.security.alpha.kubernetes.io/dind: unconfined
  labels:
    some-label: label1
spec:
  serviceAccountName: example
  securityContext:
    runAsUser: 10000
    runAsGroup: 10000
  containers: 
    - name: jnlp
      image: 'jenkins/jnlp-slave:4.3-4-alpine'
      args: ['\$(JENKINS_SECRET)', '\$(JENKINS_NAME)']
    - name: dind
      image: docker:dind
      securityContext:
          runAsUser: 0
          runAsGroup: 0
          fsGroup: 0        
          privileged: true
      tty: true
      volumeMounts:
      - name: var-run
        mountPath: /var/run
    - name: example-test
      image: pranavbhatia/example-test:0.1
      securityContext:
          runAsUser: 0
          runAsGroup: 0
          fsGroup: 0
      volumeMounts:
      - name: var-run
        mountPath: /var/run  
  volumes:
  - emptyDir: {}
    name: var-run
&quot;&quot;&quot;
        }
    }
</code></pre>
<p>Also defined a few stages -</p>
<pre><code>    stages {
        stage ('DIND') {
            steps {
                container('dind') {
                    sh 'pwd &amp;&amp; echo &quot;Pulling image&quot; &amp;&amp; docker pull ubuntu:18.04'
                }
            }
        }
        stage ('EXAMPLE') {
            steps {
                container('example-test') {
                    sh './example'
                }
            }
        }
</code></pre>
<p>So now I have this script &quot;example&quot; in my root folder and I want to run this but somehow it's not able to find it.</p>
<p>The Dockerfile looks something like this -</p>
<pre><code>FROM ubuntu:18.04

COPY ./example ./example

#make it executable
RUN chmod +x ./example

#command to keep container running in detached mode
CMD tail -f /dev/null
</code></pre>
<p><strong>pwd returns with &quot;/home/jenkins/agent/workspace/test-pipeline&quot; and not the docker container path.</strong></p>
<p>The output is as follows -</p>
<pre><code>Started by user admin
Running in Durability level: MAX_SURVIVABILITY
[Pipeline] Start of Pipeline
[Pipeline] podTemplate
[Pipeline] {
[Pipeline] node
Created Pod: test-pipeline-14-s7167-4zcg5-s68gw in namespace dc-pipeline
Still waiting to schedule task
‘test-pipeline-14-s7167-4zcg5-s68gw’ is offline
Agent test-pipeline-14-s7167-4zcg5-s68gw is provisioned from template test-pipeline_14-s7167-4zcg5
---
apiVersion: &quot;v1&quot;
kind: &quot;Pod&quot;
metadata:
  annotations:
    container.apparmor.security.beta.kubernetes.io/dind: &quot;unconfined&quot;
    container.seccomp.security.alpha.kubernetes.io/dind: &quot;unconfined&quot;
    buildUrl: &quot;http://jenkins-164-229:8080/job/test-pipeline/14/&quot;
    runUrl: &quot;job/test-pipeline/14/&quot;
  labels:
    some-label: &quot;label1&quot;
    jenkins: &quot;slave&quot;
    jenkins/label: &quot;test-pipeline_14-s7167&quot;
  name: &quot;test-pipeline-14-s7167-4zcg5-s68gw&quot;
spec:
  containers:
  - args:
    - &quot;$(JENKINS_SECRET)&quot;
    - &quot;$(JENKINS_NAME)&quot;
    env:
    - name: &quot;JENKINS_SECRET&quot;
      value: &quot;********&quot;
    - name: &quot;JENKINS_TUNNEL&quot;
      value: &quot;jenkins-164-229-agent:50000&quot;
    - name: &quot;JENKINS_AGENT_NAME&quot;
      value: &quot;test-pipeline-14-s7167-4zcg5-s68gw&quot;
    - name: &quot;JENKINS_NAME&quot;
      value: &quot;test-pipeline-14-s7167-4zcg5-s68gw&quot;
    - name: &quot;JENKINS_AGENT_WORKDIR&quot;
      value: &quot;/home/jenkins/agent&quot;
    - name: &quot;JENKINS_URL&quot;
      value: &quot;http://jenkins-164-229:8080/&quot;
    - name: &quot;HOME&quot;
      value: &quot;/home/jenkins&quot;
    image: &quot;jenkins/jnlp-slave:4.3-4-alpine&quot;
    name: &quot;jnlp&quot;
    volumeMounts:
    - mountPath: &quot;/home/jenkins/agent&quot;
      name: &quot;workspace-volume&quot;
      readOnly: false
  - image: &quot;pranavbhatia/example-test:0.1&quot;
    name: &quot;example-test&quot;
    securityContext:
      runAsGroup: 0
      runAsUser: 0
    volumeMounts:
    - mountPath: &quot;/var/run&quot;
      name: &quot;var-run&quot;
    - mountPath: &quot;/home/jenkins/agent&quot;
      name: &quot;workspace-volume&quot;
      readOnly: false
  - image: &quot;docker:dind&quot;
    name: &quot;dind&quot;
    securityContext:
      privileged: true
      runAsGroup: 0
      runAsUser: 0
    tty: true
    volumeMounts:
    - mountPath: &quot;/var/run&quot;
      name: &quot;var-run&quot;
    - mountPath: &quot;/home/jenkins/agent&quot;
      name: &quot;workspace-volume&quot;
      readOnly: false
  nodeSelector:
    beta.kubernetes.io/os: &quot;linux&quot;
  restartPolicy: &quot;Never&quot;
  securityContext:
    runAsGroup: 10000
    runAsUser: 10000
  serviceAccountName: &quot;example&quot;
  volumes:
  - emptyDir: {}
    name: &quot;var-run&quot;
  - emptyDir:
      medium: &quot;&quot;
    name: &quot;workspace-volume&quot;

Running on test-pipeline-14-s7167-4zcg5-s68gw in /home/jenkins/agent/workspace/test-pipeline
[Pipeline] {
[Pipeline] stage
[Pipeline] { (DIND)
[Pipeline] container
[Pipeline] {
[Pipeline] sh
+ pwd
/home/jenkins/agent/workspace/test-pipeline
+ echo 'Pulling image'
Pulling image
+ docker pull ubuntu:18.04
18.04: Pulling from library/ubuntu
7595c8c21622: Pulling fs layer
d13af8ca898f: Pulling fs layer
70799171ddba: Pulling fs layer
b6c12202c5ef: Pulling fs layer
b6c12202c5ef: Waiting
d13af8ca898f: Verifying Checksum
d13af8ca898f: Download complete
70799171ddba: Verifying Checksum
70799171ddba: Download complete
b6c12202c5ef: Verifying Checksum
b6c12202c5ef: Download complete
7595c8c21622: Verifying Checksum
7595c8c21622: Download complete
7595c8c21622: Pull complete
d13af8ca898f: Pull complete
70799171ddba: Pull complete
b6c12202c5ef: Pull complete
Digest: sha256:a61728f6128fb4a7a20efaa7597607ed6e69973ee9b9123e3b4fd28b7bba100b
Status: Downloaded newer image for ubuntu:18.04
docker.io/library/ubuntu:18.04
[Pipeline] }
[Pipeline] // container
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (EXAMPLE)
[Pipeline] container
[Pipeline] {
[Pipeline] sh
+ pwd
/home/jenkins/agent/workspace/test-pipeline
+ ./example
/home/jenkins/agent/workspace/test-pipeline@tmp/durable-26584660/script.sh: 1: /home/jenkins/agent/workspace/test-pipeline@tmp/durable-26584660/script.sh: ./example: not found
[Pipeline] }
[Pipeline] // container
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] }
[Pipeline] // podTemplate
[Pipeline] End of Pipeline
ERROR: script returned exit code 127
Finished: FAILURE
</code></pre>
<p>Any idea on how to fix this?</p>

Pranav Bhatia
<p>It may work to execute it with sh '/example' (without the dot). You installed it in the root filesystem, but when commands within the container are run from Jenkins the PWD will be the workspace.</p>
