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

          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' .

          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' } }

          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 added a comment -

          Sounds like a variant of JENKINS-33510; the dir step is not supported in this context, but the plugin fails to warn you that.

          The solution is trivial: cd in your shell script.

          Jesse Glick added a comment - Sounds like a variant of JENKINS-33510 ; the dir step is not supported in this context, but the plugin fails to warn you that. The solution is trivial: cd in your shell script.

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

              Created:
              Updated:
              Resolved: