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

Dir Step doesn't work inside container step when dir is outside the workspace

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: Major Major
    • kubernetes-plugin
    • None

       

      When i use a dir step inside the container step i get allways a

      error:
      ERROR: script returned exit code -2
      Finished: FAILURE
      jenkinsfile

      #!/usr/bin/env groovy
      
       node {
         deleteDir()
         checkout scm
      
         def uniqueId = UUID.randomUUID().toString()
       
         stage('testing') {
           podTemplate(
             name: env.jaas_owner + '-jaas',
             label: uniqueId,
             containers: [
               containerTemplate(
                 name: 'busybox',
                 image: 'busybox',
                 command: 'cat'
               )
             ]
           )
             {
               node(uniqueId) {
                 container('busybox') {
                   sh '''
                   cd /var
                   ls -al
                   '''
      
                   dir ('/var'){
                     sh '''
                     cd /var
                     ls -al
                     '''
                   }
                 }
               }
           }
         }
       }

       

       

          [JENKINS-47305] Dir Step doesn't work inside container step when dir is outside the workspace

          Gordon Franke created issue -

          Carlos Sanchez added a comment - Please paste debug logs https://github.com/jenkinsci/kubernetes-plugin#debugging

          Carlos Sanchez added a comment - versions ? this test is passing https://github.com/jenkinsci/kubernetes-plugin/blob/master/src/test/resources/org/csanchez/jenkins/plugins/kubernetes/pipeline/runDirContext.groovy

          Gordon Franke added a comment -

          Jenkins ver. 2.60.3

          org.csanchez.jenkins.plugins:kubernetes:1.0

           

          your test works. also absolute and relative path. but something out of the workspace didn't work for example '/home' .

          Gordon Franke added a comment - Jenkins ver. 2.60.3 org.csanchez.jenkins.plugins:kubernetes:1.0   your test works. also absolute and relative path. but something out of the workspace didn't work for example '/home' .
          Carlos Sanchez made changes -
          Summary Original: Dir Step doesn't work inside container step New: Dir Step doesn't work inside container step when dir is outside the workspace

          Max k added a comment -

          I have simillar proble with dir inside dir statement in workspace:
          dir ('dirName'){
          dir ('dirName2')

          { sh 'ls -la' }

          }

          Max k added a comment - I have simillar proble with dir inside dir statement in workspace: dir ('dirName'){ dir ('dirName2') { sh 'ls -la' } }
          Imran Noor Mohamed made changes -
          Description Original:  

          When i use a dir step inside the container step i get allways a

          error:
          ERROR: script returned exit code -2
          Finished: FAILURE
          jenkinsfile
          {code:java}
          #!/usr/bin/env groovy

           node {
             deleteDir()
             checkout scm

             def uniqueId = UUID.randomUUID().toString()
           
             stage('testing') {
               podTemplate(
                 name: env.jaas_owner + '-jaas',
                 label: uniqueId,
                 containers: [
                   containerTemplate(
                     name: 'busybox',
                     image: 'busybox',
                     command: 'cat'
                   )
                 ]
               )
                 {
                   node(uniqueId) {
                     container('busybox') {
                       sh '''
                       cd /var
                       ls -al
                       '''

                       dir ('/var'){
                         sh '''
                         cd /var
                         ls -al
                         '''
                       }
                     }
                   }
               }
             }
           }{code}
           

           
          New:  

          When i use a dir step inside the container step i get allways a

          error:
          ERROR: script returned exit code -2
          Finished: FAILURE
          jenkinsfile
          {code:java}
          #!/usr/bin/env groovy

           node {
             deleteDir()
             checkout scm

             def uniqueId = UUID.randomUUID().toString()
           
             stage('testing') {
               podTemplate(
                 name: env.jaas_owner + '-jaas',
                 label: uniqueId,
                 containers: [
                   containerTemplate(
                     name: 'busybox',
                     image: 'busybox',
                     command: 'cat'
                   )
                 ]
               )
                 {
                   node(uniqueId) {
                     container('busybox') {
                       sh '''
                       cd /var
                       ls -al
                       '''

                       dir ('/var'){
                         sh '''
                         cd /var
                         ls -al
                         '''
                       }
                     }
                   }
               }
             }
           }{code}
           

           

          J Knurek added a comment -

          Is this also the same issue as JENKINS-46055

          J Knurek added a comment - Is this also the same issue as  JENKINS-46055

          Jonas Falck added a comment - - edited

          This seems to be an issue if we use multiple containers with container('golang'){
          dir("/go")
          }

          Then the dir command seems to do it in jnlp container so i get a error that /go does not exist.

          Please also note that environment variables existing in container golang is "null" if used
          container('golang'){
          dir("${env.GOPATH}") <-- tries to cd into pwd()/null
          sh("echo $GOPATH" <-- echoes /go (WORKS)
          }

          Jonas Falck added a comment - - edited This seems to be an issue if we use multiple containers with container('golang'){ dir("/go") } Then the dir command seems to do it in jnlp container so i get a error that /go does not exist. Please also note that environment variables existing in container golang is "null" if used container('golang'){ dir("${env.GOPATH}") <-- tries to cd into pwd()/null sh("echo $GOPATH" <-- echoes /go (WORKS) }
          Jesse Glick made changes -
          Assignee Original: Carlos Sanchez [ csanchez ]

            Unassigned Unassigned
            gimler Gordon Franke
            Votes:
            0 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated:
              Resolved: