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

dir() does not change directory when used insider docker.inside block

XMLWordPrintable

      If you use dir() inside a docker.inside block - it will not work as expected.

      Take the following script, which works as expected with dir():

      node("docker") {    
              deleteDir()
                  stage 'build blueocean'   
                    dir('blueocean') {
                      git url: 'https://github.com/jenkinsci/blueocean-plugin.git'
                      sh 'ls -lah'
                    }           
                                
                  
                  stage 'prepare acceptance test harness'              
                      dir("acceptance") {
                        git url: 'https://github.com/cloudbees/blueocean-acceptance-test.git', branch: 'master'        
                        sh 'ls -lah'
                      }
                  
      }
      

      The contents of ear dir are correct. However, tweaking it slightly:

      node("docker") {    
              deleteDir()
              docker.image('cloudbees/java-build-tools').inside {
                  stage 'build blueocean'   
                    dir('blueocean') {
                      git url: 'https://github.com/jenkinsci/blueocean-plugin.git'
                      sh 'ls -lah'
                    }           
                                
                  
                  stage 'prepare acceptance test harness'              
                      dir("acceptance") {
                        git url: 'https://github.com/cloudbees/blueocean-acceptance-test.git', branch: 'master'        
                        sh 'ls -lah'
                      }
                      
              }
      }
      

      And the listings show a level above the dir, even though each dir is created, ie:

      + ls -lah
      total 16K
      drwxrwxr-x  4 jenkins jenkins 4.0K Jun 10 05:24 .
      drwxr-xr-x  4 root    root    4.0K Jun 10 05:24 ..
      drwxrwxr-x 13 jenkins jenkins 4.0K Jun 10 05:24 blueocean
      drwxrwxr-x  3 jenkins jenkins 4.0K Jun 10 05:24 blueocean@tmp
      
      ..
      
      + ls -lah
      total 24K
      drwxrwxr-x  6 jenkins jenkins 4.0K Jun 10 05:24 .
      drwxr-xr-x  4 root    root    4.0K Jun 10 05:24 ..
      drwxrwxr-x  4 jenkins jenkins 4.0K Jun 10 05:24 acceptance
      drwxrwxr-x  3 jenkins jenkins 4.0K Jun 10 05:24 acceptance@tmp
      drwxrwxr-x 13 jenkins jenkins 4.0K Jun 10 05:24 blueocean
      drwxrwxr-x  2 jenkins jenkins 4.0K Jun 10 05:24 blueocean@tmp
      

      Just a little bit maddening as I thought I was going insane.
      dir outside of docker block works just fine, as expected.

            jglick Jesse Glick
            michaelneale Michael Neale
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: