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

Details

    Description

      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
          ])
      }
      

      Attachments

        Issue Links

          Activity

            0x89 Martin Sander created issue -
            jglick Jesse Glick made changes -
            Field Original Value New Value
            Component/s workflow-cps-plugin [ 21713 ]
            Component/s pipeline [ 21692 ]
            Component/s workflow-multibranch-plugin [ 21465 ]
            jglick Jesse Glick made changes -
            Component/s workflow-multibranch-plugin [ 21465 ]
            jglick Jesse Glick made changes -
            Link This issue duplicates JENKINS-36453 [ JENKINS-36453 ]
            jglick Jesse Glick made changes -
            Resolution Duplicate [ 3 ]
            Status Open [ 1 ] Resolved [ 5 ]

            People

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

              Dates

                Created:
                Updated:
                Resolved: