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

job directory empty when using declarative pipeline

    Details

    • Type: Bug
    • Status: Closed (View Workflow)
    • Priority: Minor
    • Resolution: Duplicate
    • Labels:
      None
    • Environment:
    • Similar Issues:

      Description

      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.

        Attachments

          Issue Links

            Activity

            Hide
            wyardley Will Yardley added a comment - - edited

            If I print out env.WORKSPACE either inside or outside of the script block, I get the same value as Running on Jenkins in /var/lib/jenkins/workspace/foo_pipeline-XXXXX, but that directory is empty if I don't clean it out after builds, whereas the one with @script has the checked out copy.

            I tried adding a checkout SCM stage, then I get:
            ERROR: Could not determine exact tip revision of pipeline

            Show
            wyardley Will Yardley added a comment - - edited If I print out env.WORKSPACE either inside or outside of the script block, I get the same value as Running on Jenkins in /var/lib/jenkins/workspace/foo_pipeline-XXXXX , but that directory is empty if I don't clean it out after builds, whereas the one with @script has the checked out copy. I tried adding a checkout SCM stage, then I get: ERROR: Could not determine exact tip revision of pipeline
            Hide
            wyardley Will Yardley added a comment -

            I don't think this is a dupe of JENKINS-40862 – the error in the comment only shows up if I try to work around the problem by adding "checkout scm" in the Jenkinsfile.

            Show
            wyardley Will Yardley added a comment - I don't think this is a dupe of JENKINS-40862 – the error in the comment only shows up if I try to work around the problem by adding "checkout scm" in the Jenkinsfile.
            Hide
            abayer Andrew Bayer added a comment -

            Will Yardley - so I'm 99% sure that this is the same thing. We do an automatic checkout scm whenever you go to a new agent, but only if the skipDefaultCheckout option isn't specified and the scm object exists/is valid. The Could not determine exact tip revision of pipeline error message is, basically, what happens when you try to do a checkout scm on a null or otherwise broken scm object - you don't see that show up without the explicit checkout scm because Declarative doesn't even try doing it when the scm object is null/invalid.

            Show
            abayer Andrew Bayer added a comment - Will Yardley - so I'm 99% sure that this is the same thing. We do an automatic checkout scm whenever you go to a new agent, but only if the skipDefaultCheckout option isn't specified and the scm object exists/is valid. The Could not determine exact tip revision of pipeline error message is, basically, what happens when you try to do a checkout scm on a null or otherwise broken scm object - you don't see that show up without the explicit checkout scm because Declarative doesn't even try doing it when the scm object is null/invalid.
            Hide
            wyardley Will Yardley added a comment -

            Andrew Bayer In the case where it's not explicit, the code does get checked out, though. Just that it ends up in foo@script instead of foo. So the code gets checked out, just not to the place where Jenkins expects it to be.

            Show
            wyardley Will Yardley added a comment - Andrew Bayer In the case where it's not explicit, the code does get checked out, though. Just that it ends up in foo@script instead of foo . So the code gets checked out, just not to the place where Jenkins expects it to be.
            Hide
            bitwiseman Liam Newman added a comment -

            Bulk closing resolved issues.

            Show
            bitwiseman Liam Newman added a comment - Bulk closing resolved issues.

              People

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

                Dates

                • Created:
                  Updated:
                  Resolved: