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

            Hide
            duemir Denys Digtiar added a comment - - edited

            Attila Szeremi If you Docker Pipeline plugin is 1.15 and Docker is 17.12 or newer then everything should just work no need to change the Pipeline. That is if I understand the fix correctly.

            Show
            duemir Denys Digtiar added a comment - - edited Attila Szeremi If you Docker Pipeline plugin is 1.15 and Docker is 17.12 or newer then everything should just work no need to change the Pipeline. That is if I understand the fix correctly.
            Hide
            amcsi Attila Szeremi added a comment - - edited

            Denys Digtiar I have Docker Pipeline plugin 1.17, and Docker version 18.09.0. And doing dir in my Jenkinsfile got me...

             

             

            [Pipeline] {
            [Pipeline] stage
            [Pipeline] { (Run tests)
            [Pipeline] dir
            Running in /var/www
            [Pipeline] {
            [Pipeline] sh
            [Pipeline] }
            [Pipeline] // dir
            [Pipeline] }
            [Pipeline] // stage
            [Pipeline] }
            $ docker stop --time=1 baa0c2d74c1fdc4944eb4e0bb5eb57f8435caac1a2e28ab562140bb3e0daaf38
            $ docker rm -f baa0c2d74c1fdc4944eb4e0bb5eb57f8435caac1a2e28ab562140bb3e0daaf38
            [Pipeline] // withDockerContainer
            [Pipeline] }
            [Pipeline] // withEnv
            [Pipeline] }
            [Pipeline] // node
            [Pipeline] End of Pipeline
            
            GitHub has been notified of this commit’s build result
            
            java.nio.file.AccessDeniedException: /var/www@tmp
            	at sun.nio.fs.UnixException.translateToIOException(UnixException.java:84)
            	at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:102)
            	at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:107)
            	at sun.nio.fs.UnixFileSystemProvider.createDirectory(UnixFileSystemProvider.java:384)
            	at java.nio.file.Files.createDirectory(Files.java:674)
            	at java.nio.file.Files.createAndCheckIsDirectory(Files.java:781)
            	at java.nio.file.Files.createDirectories(Files.java:767)
            	at hudson.FilePath.mkdirs(FilePath.java:3273)
            	at hudson.FilePath.access$1300(FilePath.java:213)
            	at hudson.FilePath$Mkdirs.invoke(FilePath.java:1254)
            	at hudson.FilePath$Mkdirs.invoke(FilePath.java:1250)
            	at hudson.FilePath.act(FilePath.java:1078)
            	at hudson.FilePath.act(FilePath.java:1061)
            	at hudson.FilePath.mkdirs(FilePath.java:1246)
            	at org.jenkinsci.plugins.durabletask.FileMonitoringTask$FileMonitoringController.<init>(FileMonitoringTask.java:174)
            	at org.jenkinsci.plugins.durabletask.BourneShellScript$ShellController.<init>(BourneShellScript.java:200)
            	at org.jenkinsci.plugins.durabletask.BourneShellScript$ShellController.<init>(BourneShellScript.java:192)
            	at org.jenkinsci.plugins.durabletask.BourneShellScript.launchWithCookie(BourneShellScript.java:110)
            	at org.jenkinsci.plugins.durabletask.FileMonitoringTask.launch(FileMonitoringTask.java:99)
            	at org.jenkinsci.plugins.workflow.steps.durable_task.DurableTaskStep$Execution.start(DurableTaskStep.java:278)
            	at org.jenkinsci.plugins.workflow.cps.DSL.invokeStep(DSL.java:270)
            	at org.jenkinsci.plugins.workflow.cps.DSL.invokeMethod(DSL.java:178)
            	at org.jenkinsci.plugins.workflow.cps.CpsScript.invokeMethod(CpsScript.java:122)
            	at sun.reflect.GeneratedMethodAccessor312.invoke(Unknown Source)
            	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
            	at java.lang.reflect.Method.invoke(Method.java:498)
            	at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93)
            	at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
            	at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1213)
            	at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1022)
            	at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:42)
            	at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
            	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
            	at org.kohsuke.groovy.sandbox.impl.Checker$1.call(Checker.java:157)
            	at org.kohsuke.groovy.sandbox.GroovyInterceptor.onMethodCall(GroovyInterceptor.java:23)
            	at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onMethodCall(SandboxInterceptor.java:155)
            	at org.kohsuke.groovy.sandbox.impl.Checker$1.call(Checker.java:155)
            	at org.kohsuke.groovy.sandbox.impl.Checker.checkedCall(Checker.java:159)
            	at org.kohsuke.groovy.sandbox.impl.Checker.checkedCall(Checker.java:129)
            	at org.kohsuke.groovy.sandbox.impl.Checker.checkedCall(Checker.java:129)
            	at com.cloudbees.groovy.cps.sandbox.SandboxInvoker.methodCall(SandboxInvoker.java:17)
            	at WorkflowScript.run(WorkflowScript:10)
            	at ___cps.transform___(Native Method)
            	at com.cloudbees.groovy.cps.impl.ContinuationGroup.methodCall(ContinuationGroup.java:57)
            	at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.dispatchOrArg(FunctionCallBlock.java:109)
            	at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.fixArg(FunctionCallBlock.java:82)
            	at sun.reflect.GeneratedMethodAccessor127.invoke(Unknown Source)
            	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
            	at java.lang.reflect.Method.invoke(Method.java:498)
            	at com.cloudbees.groovy.cps.impl.ContinuationPtr$ContinuationImpl.receive(ContinuationPtr.java:72)
            	at com.cloudbees.groovy.cps.impl.ConstantBlock.eval(ConstantBlock.java:21)
            	at com.cloudbees.groovy.cps.Next.step(Next.java:83)
            	at com.cloudbees.groovy.cps.Continuable$1.call(Continuable.java:174)
            	at com.cloudbees.groovy.cps.Continuable$1.call(Continuable.java:163)
            	at org.codehaus.groovy.runtime.GroovyCategorySupport$ThreadCategoryInfo.use(GroovyCategorySupport.java:129)
            	at org.codehaus.groovy.runtime.GroovyCategorySupport.use(GroovyCategorySupport.java:268)
            	at com.cloudbees.groovy.cps.Continuable.run0(Continuable.java:163)
            	at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.access$101(SandboxContinuable.java:34)
            	at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.lambda$run0$0(SandboxContinuable.java:59)
            	at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.GroovySandbox.runInSandbox(GroovySandbox.java:108)
            	at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.run0(SandboxContinuable.java:58)
            	at org.jenkinsci.plugins.workflow.cps.CpsThread.runNextChunk(CpsThread.java:182)
            	at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.run(CpsThreadGroup.java:332)
            	at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.access$200(CpsThreadGroup.java:83)
            	at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:244)
            	at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:232)
            	at org.jenkinsci.plugins.workflow.cps.CpsVmExecutorService$2.call(CpsVmExecutorService.java:64)
            	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
            	at hudson.remoting.SingleLaneExecutorService$1.run(SingleLaneExecutorService.java:131)
            	at jenkins.util.ContextResettingExecutorService$1.run(ContextResettingExecutorService.java:28)
            	at jenkins.security.ImpersonatingExecutorService$1.run(ImpersonatingExecutorService.java:59)
            	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
            	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
            	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
            	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
            	at java.lang.Thread.run(Thread.java:748)
            Finished: FAILURE

             

            Show
            amcsi Attila Szeremi added a comment - - edited Denys Digtiar I have Docker Pipeline plugin 1.17, and Docker version 18.09.0. And doing dir in my Jenkinsfile got me...     [Pipeline] { [Pipeline] stage [Pipeline] { (Run tests) [Pipeline] dir Running in / var /www [Pipeline] { [Pipeline] sh [Pipeline] } [Pipeline] // dir [Pipeline] } [Pipeline] // stage [Pipeline] } $ docker stop --time=1 baa0c2d74c1fdc4944eb4e0bb5eb57f8435caac1a2e28ab562140bb3e0daaf38 $ docker rm -f baa0c2d74c1fdc4944eb4e0bb5eb57f8435caac1a2e28ab562140bb3e0daaf38 [Pipeline] // withDockerContainer [Pipeline] } [Pipeline] // withEnv [Pipeline] } [Pipeline] // node [Pipeline] End of Pipeline GitHub has been notified of this commit’s build result java.nio.file.AccessDeniedException: / var /www@tmp at sun.nio.fs.UnixException.translateToIOException(UnixException.java:84) at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:102) at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:107) at sun.nio.fs.UnixFileSystemProvider.createDirectory(UnixFileSystemProvider.java:384) at java.nio.file.Files.createDirectory(Files.java:674) at java.nio.file.Files.createAndCheckIsDirectory(Files.java:781) at java.nio.file.Files.createDirectories(Files.java:767) at hudson.FilePath.mkdirs(FilePath.java:3273) at hudson.FilePath.access$1300(FilePath.java:213) at hudson.FilePath$Mkdirs.invoke(FilePath.java:1254) at hudson.FilePath$Mkdirs.invoke(FilePath.java:1250) at hudson.FilePath.act(FilePath.java:1078) at hudson.FilePath.act(FilePath.java:1061) at hudson.FilePath.mkdirs(FilePath.java:1246) at org.jenkinsci.plugins.durabletask.FileMonitoringTask$FileMonitoringController.<init>(FileMonitoringTask.java:174) at org.jenkinsci.plugins.durabletask.BourneShellScript$ShellController.<init>(BourneShellScript.java:200) at org.jenkinsci.plugins.durabletask.BourneShellScript$ShellController.<init>(BourneShellScript.java:192) at org.jenkinsci.plugins.durabletask.BourneShellScript.launchWithCookie(BourneShellScript.java:110) at org.jenkinsci.plugins.durabletask.FileMonitoringTask.launch(FileMonitoringTask.java:99) at org.jenkinsci.plugins.workflow.steps.durable_task.DurableTaskStep$Execution.start(DurableTaskStep.java:278) at org.jenkinsci.plugins.workflow.cps.DSL.invokeStep(DSL.java:270) at org.jenkinsci.plugins.workflow.cps.DSL.invokeMethod(DSL.java:178) at org.jenkinsci.plugins.workflow.cps.CpsScript.invokeMethod(CpsScript.java:122) at sun.reflect.GeneratedMethodAccessor312.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93) at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325) at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1213) at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1022) at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:42) at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113) at org.kohsuke.groovy.sandbox.impl.Checker$1.call(Checker.java:157) at org.kohsuke.groovy.sandbox.GroovyInterceptor.onMethodCall(GroovyInterceptor.java:23) at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onMethodCall(SandboxInterceptor.java:155) at org.kohsuke.groovy.sandbox.impl.Checker$1.call(Checker.java:155) at org.kohsuke.groovy.sandbox.impl.Checker.checkedCall(Checker.java:159) at org.kohsuke.groovy.sandbox.impl.Checker.checkedCall(Checker.java:129) at org.kohsuke.groovy.sandbox.impl.Checker.checkedCall(Checker.java:129) at com.cloudbees.groovy.cps.sandbox.SandboxInvoker.methodCall(SandboxInvoker.java:17) at WorkflowScript.run(WorkflowScript:10) at ___cps.transform___(Native Method) at com.cloudbees.groovy.cps.impl.ContinuationGroup.methodCall(ContinuationGroup.java:57) at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.dispatchOrArg(FunctionCallBlock.java:109) at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.fixArg(FunctionCallBlock.java:82) at sun.reflect.GeneratedMethodAccessor127.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at com.cloudbees.groovy.cps.impl.ContinuationPtr$ContinuationImpl.receive(ContinuationPtr.java:72) at com.cloudbees.groovy.cps.impl.ConstantBlock.eval(ConstantBlock.java:21) at com.cloudbees.groovy.cps.Next.step(Next.java:83) at com.cloudbees.groovy.cps.Continuable$1.call(Continuable.java:174) at com.cloudbees.groovy.cps.Continuable$1.call(Continuable.java:163) at org.codehaus.groovy.runtime.GroovyCategorySupport$ThreadCategoryInfo.use(GroovyCategorySupport.java:129) at org.codehaus.groovy.runtime.GroovyCategorySupport.use(GroovyCategorySupport.java:268) at com.cloudbees.groovy.cps.Continuable.run0(Continuable.java:163) at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.access$101(SandboxContinuable.java:34) at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.lambda$run0$0(SandboxContinuable.java:59) at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.GroovySandbox.runInSandbox(GroovySandbox.java:108) at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.run0(SandboxContinuable.java:58) at org.jenkinsci.plugins.workflow.cps.CpsThread.runNextChunk(CpsThread.java:182) at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.run(CpsThreadGroup.java:332) at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.access$200(CpsThreadGroup.java:83) at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:244) at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:232) at org.jenkinsci.plugins.workflow.cps.CpsVmExecutorService$2.call(CpsVmExecutorService.java:64) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at hudson.remoting.SingleLaneExecutorService$1.run(SingleLaneExecutorService.java:131) at jenkins.util.ContextResettingExecutorService$1.run(ContextResettingExecutorService.java:28) at jenkins.security.ImpersonatingExecutorService$1.run(ImpersonatingExecutorService.java:59) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at java.lang. Thread .run( Thread .java:748) Finished: FAILURE  
            Hide
            duemir Denys Digtiar added a comment -

            Attila Szeremi So the defect indeed looks fixed and the issue appears to be with the file access now. Jenkins is trying to create a temp working directory besides the current working directory to write a shell script to but doesn't seem to have access to the `/var` directory. I would recommend reaching out to the mailing list or StackOverflow to get help with it if you have not yet solved it.

            Show
            duemir Denys Digtiar added a comment - Attila Szeremi So the defect indeed looks fixed and the issue appears to be with the file access now. Jenkins is trying to create a temp working directory besides the current working directory to write a shell script to but doesn't seem to have access to the `/var` directory. I would recommend reaching out to the mailing list or StackOverflow to get help with it if you have not yet solved it.
            Hide
            amcsi Attila Szeremi added a comment - - edited

            Denys Digtiar oh, so it needs to create a directory like that as a sort of preparation.

            But it doesn't make sense to me how it's expecting for the parent of the workdir to be writable.

            I thought `/var/www` is fine for a workdir, but of course `/var` wouldn't be writable to the default user under normal circumstances. A popular article suggests to use `/app` as the workdir, where of course `/` wouldn't be writable. Why isn't Docker writing to `/var/tmp` instead which is writable? What am I (or others) expected to do instead?

             

            Show
            amcsi Attila Szeremi added a comment - - edited Denys Digtiar oh, so it needs to create a directory like that as a sort of preparation. But it doesn't make sense to me how it's expecting for the parent of the workdir to be writable. I thought `/var/www` is fine for a workdir, but of course `/var` wouldn't be writable to the default user under normal circumstances. A popular article suggests to use `/app` as the workdir, where of course `/` wouldn't be writable. Why isn't Docker writing to `/var/tmp` instead which is writable? What am I (or others) expected to do instead?  
            Hide
            jglick Jesse Glick added a comment -

            Attila Szeremi dir with an absolute path is not supported inside a Docker container. Not really related to this issue. Simply start your sh script with cd. Or avoid using the withDockerContainer step alogether—if it works perfectly for you out of the box, great, otherwise forget about it.

            Show
            jglick Jesse Glick added a comment - Attila Szeremi dir with an absolute path is not supported inside a Docker container. Not really related to this issue. Simply start your sh script with cd . Or avoid using the withDockerContainer step alogether—if it works perfectly for you out of the box, great, otherwise forget about it.

              People

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

                Dates

                • Created:
                  Updated:
                  Resolved: