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

job directory empty when using declarative pipeline

XMLWordPrintable

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

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

              Created:
              Updated:
              Resolved: