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

checkout with commitID does not work in sharedlibaray of pipeline

      in the pipeline step: checkout step, use "branches to build" with commitID
      generated by snippet and it works:
      node('master'){
      stage("1")

      { checkout changelog: true, poll: true, scm: [$class: 'GitSCM', branches: [[name: 'fc5c534716c171a03eeb31a12c1e0acff700dcbf']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[url: 'ssh://git@gitlab.is.com:7999/myRepo']]] }

      }
      but same code in the shared library does not work:
      class Git implements Serializable {
      def checkoutScm()

      { checkout changelog: true, poll: true, scm: [$class: 'GitSCM', branches: [[name: 'fc5c534716c171a03eeb31a12c1e0acff700dcbf']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[url: 'ssh://git@gitlab.is.com:7999/myRepo']]] }

      }
      }
      node('master'){
      stage("1"){
      def git = new Git()
      git.checkoutScm()

      Compared with the console, the difference in the later is:
      Fetching upstream changes from ssh://git@gitlab.is.com:7999/myRepo.git
      > /usr/bin/git fetch --tags --progress ssh://git@gitlab.is.com:7999/myRepo.git +refs/heads/:refs/remotes/origin/
      > /usr/bin/git rev-parse refs/remotes/origin/fc5c534716c171a03eeb31a12c1e0acff700dcbf^

      {commit} # timeout=10
      > /usr/bin/git rev-parse refs/remotes/origin/origin/fc5c534716c171a03eeb31a12c1e0acff700dcbf^{commit}

      # timeout=10
      > /usr/bin/git rev-parse origin/fc5c534716c171a03eeb31a12c1e0acff700dcbf^

      {commit} # timeout=10



      I assume, git rev-parse should done as
      /usr/bin/git rev-parse fc5c534716c171a03eeb31a12c1e0acff700dcbf^{commit}

      when the input is a commitId than a real branch name
      so why it tries "refs/remote/origin", " refs/remote/origin/origin", "origin" instead?

          [JENKINS-40039] checkout with commitID does not work in sharedlibaray of pipeline

          Andrew Bayer added a comment -

          What's the path for your shared library file? If it's in src/..., that's expected. You shouldn't call steps (like checkout) from classes in src/....

          Andrew Bayer added a comment - What's the path for your shared library file? If it's in src/... , that's expected. You shouldn't call steps (like checkout ) from classes in src/... .

            Unassigned Unassigned
            zdtsw_1 Wen Zhou
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: