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

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

    XMLWordPrintable

Details

    Description

       

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

       

       

      Attachments

        Issue Links

          Activity

            csanchez Carlos Sanchez added a comment - Please paste debug logs https://github.com/jenkinsci/kubernetes-plugin#debugging
            csanchez 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
            gimler 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' .

            gimler 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' .
            omegam Max k added a comment -

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

            { sh 'ls -la' }

            }

            omegam Max k added a comment - I have simillar proble with dir inside dir statement in workspace: dir ('dirName'){ dir ('dirName2') { sh 'ls -la' } }
            jknurek J Knurek added a comment -

            Is this also the same issue as JENKINS-46055

            jknurek J Knurek added a comment - Is this also the same issue as  JENKINS-46055
            jonaz 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)
            }

            jonaz 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) }
            jglick 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.

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

            People

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

              Dates

                Created:
                Updated:
                Resolved: