Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-33510

dir('foo') inside "docker.image().inside{}" does not affect CWD of launched processes

    XMLWordPrintable

    Details

    • Similar Issues:

      Description

      The "dir('foo')" step inside "docker.image('my-image').inside" creates a directory "foo@tmp" instead of changing the current directory as expected.

      In the test below, ">>> SHOULD LS THE foo DIR" is showing an "ls" is the parent dir instead of changing to the "foo" dir and we see a dir "foo@tmp" that have been created.

      This problem is specific to "docker.image('my-image').inside", it does not happen with a standard "node".

      docker.image('cloudbees/java-build-tools:0.0.7.1').inside {
          sh 'rm -rf foo*' // RE INIT TEST
          println '>>> LS THE PARENT DIR'
          sh 'mkdir -p foo/bar'
          sh 'ls -al'
          dir('foo') {
              println '>>> SHOULD LS THE foo DIR'
              sh 'ls -al'
          }
      }
      
      Started by user admin
      [Pipeline] Allocate node : Start
      Running on jenkins-agent.beesshop.org in /home/ubuntu/jenkins-aws-home/workspace/tests/test-change-dir-4
      [Pipeline] node {
      [Pipeline] sh
      [test-change-dir-4] Running shell script
      + docker inspect -f . cloudbees/java-build-tools:0.0.7.1
      .
      [Pipeline] Run build steps inside a Docker container : Start
      $ docker run -t -d -u 1000:1000 -w /home/ubuntu/jenkins-aws-home/workspace/tests/test-change-dir-4 -v /home/ubuntu/jenkins-aws-home/workspace/tests/test-change-dir-4:/home/ubuntu/jenkins-aws-home/workspace/tests/test-change-dir-4:rw -v /home/ubuntu/jenkins-aws-home/workspace/tests/test-change-dir-4@tmp:/home/ubuntu/jenkins-aws-home/workspace/tests/test-change-dir-4@tmp:rw -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** cloudbees/java-build-tools:0.0.7.1 cat
      [Pipeline] withDockerContainer {
      [Pipeline] sh
      [test-change-dir-4] Running shell script
      + rm -rf foo foo@tmp
      [Pipeline] echo
      >>> LS THE PARENT DIR
      [Pipeline] sh
      [test-change-dir-4] Running shell script
      + mkdir -p foo/bar
      [Pipeline] sh
      [test-change-dir-4] Running shell script
      + ls -al
      total 12
      drwxrwxr-x 3 jenkins jenkins 4096 Mar 13 21:50 .
      drwxr-xr-x 4 root    root    4096 Mar 13 21:50 ..
      drwxr-xr-x 3 jenkins jenkins 4096 Mar 13 21:50 foo
      [Pipeline] Change current directory : Start
      Running in /home/ubuntu/jenkins-aws-home/workspace/tests/test-change-dir-4/foo
      [Pipeline] dir {
      [Pipeline] echo
      >>> SHOULD LS THE foo DIR
      [Pipeline] sh
      [foo] Running shell script
      + ls -al
      total 16
      drwxrwxr-x 4 jenkins jenkins 4096 Mar 13 21:50 .
      drwxr-xr-x 4 root    root    4096 Mar 13 21:50 ..
      drwxr-xr-x 3 jenkins jenkins 4096 Mar 13 21:50 foo
      drwxrwxr-x 3 jenkins jenkins 4096 Mar 13 21:50 foo@tmp
      [Pipeline] } //dir
      [Pipeline] Change current directory : End
      

        Attachments

          Issue Links

            Activity

            Show
            ndeloof Nicolas De Loof added a comment - see  https://github.com/jenkinsci/docker-workflow-plugin/pull/123
            Hide
            scm_issue_link SCM/JIRA link daemon added a comment -

            Code changed in jenkins
            User: Nicolas De Loof
            Path:
            src/main/java/org/jenkinsci/plugins/docker/workflow/WithContainerStep.java
            src/test/java/org/jenkinsci/plugins/docker/workflow/WithContainerStepTest.java
            http://jenkins-ci.org/commit/docker-workflow-plugin/983287324927b65d754174176c0c26ebdeffece9
            Log:
            [FIX JENKINS-33510] exec --workdir has been introduced in docker 17.12

            Show
            scm_issue_link SCM/JIRA link daemon added a comment - Code changed in jenkins User: Nicolas De Loof Path: src/main/java/org/jenkinsci/plugins/docker/workflow/WithContainerStep.java src/test/java/org/jenkinsci/plugins/docker/workflow/WithContainerStepTest.java http://jenkins-ci.org/commit/docker-workflow-plugin/983287324927b65d754174176c0c26ebdeffece9 Log: [FIX JENKINS-33510] exec --workdir has been introduced in docker 17.12
            Hide
            scm_issue_link SCM/JIRA link daemon added a comment -

            Code changed in jenkins
            User: Andrew Bayer
            Path:
            src/main/java/org/jenkinsci/plugins/docker/workflow/WithContainerStep.java
            src/test/java/org/jenkinsci/plugins/docker/workflow/WithContainerStepTest.java
            http://jenkins-ci.org/commit/docker-workflow-plugin/5aa1db202fd263e5bdc1cf2078c7258cb8e61bb0
            Log:
            Merge pull request #123 from ndeloof/JENKINS-33510

            [FIX JENKINS-33510] exec --workdir has been introduced in docker 17.12

            Compare: https://github.com/jenkinsci/docker-workflow-plugin/compare/ed5980955403...5aa1db202fd2

            Show
            scm_issue_link SCM/JIRA link daemon added a comment - Code changed in jenkins User: Andrew Bayer Path: src/main/java/org/jenkinsci/plugins/docker/workflow/WithContainerStep.java src/test/java/org/jenkinsci/plugins/docker/workflow/WithContainerStepTest.java http://jenkins-ci.org/commit/docker-workflow-plugin/5aa1db202fd263e5bdc1cf2078c7258cb8e61bb0 Log: Merge pull request #123 from ndeloof/ JENKINS-33510 [FIX JENKINS-33510] exec --workdir has been introduced in docker 17.12 Compare: https://github.com/jenkinsci/docker-workflow-plugin/compare/ed5980955403...5aa1db202fd2
            Hide
            weakcamel Waldek M added a comment -

            I took the liberty to link JENKINS-38331 - per-stage `agent` declarations are also affected.

            Show
            weakcamel Waldek M added a comment - I took the liberty to link JENKINS-38331 - per-stage `agent` declarations are also affected.
            Hide
            michaelneale Michael Neale added a comment -

            thanks Waldek M - they most certainly are as they are using docker pipeline under the covers at the moment. 

            Show
            michaelneale Michael Neale added a comment - thanks Waldek M - they most certainly are as they are using docker pipeline under the covers at the moment. 

              People

              • Assignee:
                ndeloof Nicolas De Loof
                Reporter:
                cleclerc Cyrille Le Clerc
              • Votes:
                49 Vote for this issue
                Watchers:
                70 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: