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

job directory empty when using declarative pipeline

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: Minor Minor
    • None

      I'm creating a job with a declarative pipeline; I'm coming across an issue similar to:

      https://issues.jenkins-ci.org/browse/JENKINS-42440

      only with a declarative pipeline. Jenkins does automagically check out the code, but it ends up in a

      $WORKSPACE/foo_pipeline-XXXXX@script

      directory instead of

      $WORKSPACE/foo_pipeline-XXXXX
      giving an error like:

      Running on Jenkins in /var/lib/jenkins/workspace/foo_pipeline-XXXXX
      [...]
      java.io.FileNotFoundException: /var/lib/jenkins/workspace/foo_pipeline-XXXXX/package.json does not exist.
      	at org.jenkinsci.plugins.pipeline.utility.steps.json.ReadJSONStepExecution.doRun(ReadJSONStepExecution.java:69)
      	at org.jenkinsci.plugins.pipeline.utility.steps.json.ReadJSONStepExecution.doRun(ReadJSONStepExecution.java:45)
      	at org.jenkinsci.plugins.pipeline.utility.steps.AbstractFileOrTextStepExecution.run(AbstractFileOrTextStepExecution.java:23)
      	at org.jenkinsci.plugins.workflow.steps.AbstractSynchronousNonBlockingStepExecution$1$1.call(AbstractSynchronousNonBlockingStepExecution.java:47)
      	at hudson.security.ACL.impersonate(ACL.java:290)
      	at org.jenkinsci.plugins.workflow.steps.AbstractSynchronousNonBlockingStepExecution$1.run(AbstractSynchronousNonBlockingStepExecution.java:44)
      	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
      
      pipeline {
        agent any
        parameters {
          choice(choices: 'foo\nbar',
                 description: 'Which package to build',
                 name: 'packageType'
          )
        }
        stages {
          stage('Build and push image') {
            steps {
              script {
                // requires "Pipeline Utility Steps" plugin
                def packageJson = readJSON file:'package.json'
      
                echo "${packageJson.version}"
                // more stuff here
              }
            }
          }
      
        }
        post {
          always {
            // Uses Workspace Cleanup plugin
            cleanWs()
          }
        }
      }
      

      This was easy to miss when I wasn't clearing out the job workspace each time, but I think that would actually have been worse, since I'm guessing Jenkins was looking in one place, but running / changing things in the other.

          [JENKINS-49466] job directory empty when using declarative pipeline

          Will Yardley created issue -
          Will Yardley made changes -
          Description Original: I'm creating a job with a declarative pipeline; I'm coming across an issue similar to:

          https://issues.jenkins-ci.org/browse/JENKINS-42440

          only with a declarative pipeline. Jenkins does automagically check out the code, but it ends up in a

          {{$WORKSPACE/foo_pipeline-XXXXX@script}}

          directory instead of

          {{$WORKSPACE/foo_pipeline-XXXXX}}
          giving an error like:

          {noformat}
          Running on Jenkins in /var/lib/jenkins/workspace/foo_pipeline-XXXXX
          [...]
          java.io.FileNotFoundException: /var/lib/jenkins/workspace/foo_pipeline-XXXXX/package.json does not exist.
          at org.jenkinsci.plugins.pipeline.utility.steps.json.ReadJSONStepExecution.doRun(ReadJSONStepExecution.java:69)
          at org.jenkinsci.plugins.pipeline.utility.steps.json.ReadJSONStepExecution.doRun(ReadJSONStepExecution.java:45)
          at org.jenkinsci.plugins.pipeline.utility.steps.AbstractFileOrTextStepExecution.run(AbstractFileOrTextStepExecution.java:23)
          at org.jenkinsci.plugins.workflow.steps.AbstractSynchronousNonBlockingStepExecution$1$1.call(AbstractSynchronousNonBlockingStepExecution.java:47)
          at hudson.security.ACL.impersonate(ACL.java:290)
          at org.jenkinsci.plugins.workflow.steps.AbstractSynchronousNonBlockingStepExecution$1.run(AbstractSynchronousNonBlockingStepExecution.java:44)
          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
          {noformat}

          {code}
          pipeline {
            agent any
            parameters {
              choice(choices: 'foo\nbar',
                     description: 'Which package to build',
                     name: 'packageType'
              )
            }
            stages {
              stage('Build and push image') {
                steps {
                  script {
                    // requires "Pipeline Utility Steps" plugin
                    def packageJson = readJSON file:'package.json'

                    echo "${packageJson.version}"
                    // more stuff here
                  }
                }
              }

            }
            post {
              always {
                // Uses Workspace Cleanup plugin
                cleanWs()
              }
            }
          }
          {code}
          New: I'm creating a job with a declarative pipeline; I'm coming across an issue similar to:

          https://issues.jenkins-ci.org/browse/JENKINS-42440

          only with a declarative pipeline. Jenkins does automagically check out the code, but it ends up in a

          {{$WORKSPACE/foo_pipeline-XXXXX@script}}

          directory instead of

          {{$WORKSPACE/foo_pipeline-XXXXX}}
          giving an error like:

          {noformat}
          Running on Jenkins in /var/lib/jenkins/workspace/foo_pipeline-XXXXX
          [...]
          java.io.FileNotFoundException: /var/lib/jenkins/workspace/foo_pipeline-XXXXX/package.json does not exist.
          at org.jenkinsci.plugins.pipeline.utility.steps.json.ReadJSONStepExecution.doRun(ReadJSONStepExecution.java:69)
          at org.jenkinsci.plugins.pipeline.utility.steps.json.ReadJSONStepExecution.doRun(ReadJSONStepExecution.java:45)
          at org.jenkinsci.plugins.pipeline.utility.steps.AbstractFileOrTextStepExecution.run(AbstractFileOrTextStepExecution.java:23)
          at org.jenkinsci.plugins.workflow.steps.AbstractSynchronousNonBlockingStepExecution$1$1.call(AbstractSynchronousNonBlockingStepExecution.java:47)
          at hudson.security.ACL.impersonate(ACL.java:290)
          at org.jenkinsci.plugins.workflow.steps.AbstractSynchronousNonBlockingStepExecution$1.run(AbstractSynchronousNonBlockingStepExecution.java:44)
          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
          {noformat}

          {code}
          pipeline {
            agent any
            parameters {
              choice(choices: 'foo\nbar',
                     description: 'Which package to build',
                     name: 'packageType'
              )
            }
            stages {
              stage('Build and push image') {
                steps {
                  script {
                    // requires "Pipeline Utility Steps" plugin
                    def packageJson = readJSON file:'package.json'

                    echo "${packageJson.version}"
                    // more stuff here
                  }
                }
              }

            }
            post {
              always {
                // Uses Workspace Cleanup plugin
                cleanWs()
              }
            }
          }
          {code}

          This was easy to miss when I wasn't clearing out the job workspace each time, but I think that would actually have been worse, since I'm guessing Jenkins was looking in one place, but running / changing things in the other.
          Oleg Nenashev made changes -
          Component/s New: pipeline-model-definition-plugin [ 21706 ]
          Andrew Bayer made changes -
          Link New: This issue duplicates JENKINS-40862 [ JENKINS-40862 ]
          Andrew Bayer made changes -
          Resolution New: Duplicate [ 3 ]
          Status Original: Open [ 1 ] New: Resolved [ 5 ]
          Will Yardley made changes -
          Resolution Original: Duplicate [ 3 ]
          Status Original: Resolved [ 5 ] New: Reopened [ 4 ]
          Andrew Bayer made changes -
          Link New: This issue duplicates JENKINS-48571 [ JENKINS-48571 ]
          Andrew Bayer made changes -
          Resolution New: Duplicate [ 3 ]
          Status Original: Reopened [ 4 ] New: Resolved [ 5 ]
          Liam Newman made changes -
          Status Original: Resolved [ 5 ] New: Closed [ 6 ]

            Unassigned Unassigned
            wyardley Will Yardley
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: