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

"checkout scm" should give the same guarantees on standalone pipeline jobs as on multibranch jobs

XMLWordPrintable

      Disclaimer: I know that this might never get implemented, but I still would like to state that this would be an improvement...

      JENKINS-31386 implemented checkout scm for standalone jobs.
      As stated here and here and in the `scm` global variable documentation, this behaves differently from the multibranch checkout scm:

      You may also use this in a standalone project configured with Pipeline script from SCM, though in that case the checkout will just be of the latest revision in the branch, possibly newer than the revision from which the Pipeline script was loaded.

      This has the nasty side effect that your sources might not come from the same commit as your build definition.

      So the request is to give the same guarantee of always checking out the same commit when doing checkout scm also in standalone projects.

      Workaround (if you have access to currentBuild.rawBuild and you know that you are using git:

      def scmEnv = new HashMap<String, String>()
      scm.buildEnvironment(currentBuild.rawBuild, scmEnv)
      echo "$scmEnv"
      node {
          sh "sleep 5"
          echo "first"
          checkout([
                 $class: 'GitSCM',
                 branches: [[name: scmEnv.GIT_COMMIT]],
                 userRemoteConfigs: scm.userRemoteConfigs
          ])
       
          sh "sleep 5"
      }
       
      node {
          echo "second"
          checkout([
                  $class: 'GitSCM',
                  branches: [[name: scmEnv.GIT_COMMIT]],
                  userRemoteConfigs: scm.userRemoteConfigs
          ])
      }
      

            Unassigned Unassigned
            0x89 Martin Sander
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: