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

Unable to load library from GitHub PR or SHA1 using Github SCM

XMLWordPrintable

      Previous to upgrading to the GitHub branch source plugin v2.2.2, we were on 2.0.8, and the following code within a Jenkinsfile would work:

      def targetBranch = env.getEnvironment().get('CHANGE_TARGET', env.BRANCH_NAME)
      def pullNumber = env.getEnvironment().get('CHANGE_ID', null)
      def libraryVersion = (pullNumber == null) ? targetBranch : "origin/pr/$CHANGE_ID"
      
      library "kubic-jenkins-library@${libraryVersion}"
      
      ...

      This would allow us to submit a pull request to our library repo, and have the updated code loaded and used for the job.

      The logs from when this worked with 2.0.8 would look like this:

      Started by user Kiall Mac Innes
      Replayed #1
      Connecting to https://api.github.com using ********/****** (GitHub Access Token - ********)
      Obtained Jenkinsfile from 2527f5cd5e00ec77f9a833fe49db5e4d28327f5e
      [Pipeline] library
      Loading library kubic-jenkins-library@origin/pr/42
      > git rev-parse --is-inside-work-tree # timeout=10
      Setting origin to https://github.com/ourorg/jenkins-library.git
      > git config remote.origin.url https://github.com/ourorg/jenkins-library.git # timeout=10
      Fetching origin...
      Fetching upstream changes from origin
      > git --version # timeout=10
      using GIT_ASKPASS to set credentials GitHub Access Token - ********
      > git fetch --tags --progress origin +refs/heads/*:refs/remotes/origin/* +refs/pull/*/head:refs/remotes/origin/pr/*
      > git rev-parse origin/pr/42^{commit} # timeout=10
      > git rev-parse --is-inside-work-tree # timeout=10
      Fetching changes from 2 remote Git repositories
      > git config remote.origin.url https://github.com/ourorg/jenkins-library.git # timeout=10
      Fetching upstream changes from https://github.com/ourorg/jenkins-library.git
      > git --version # timeout=10
      using GIT_ASKPASS to set credentials GitHub Access Token - ********
      > git fetch --tags --progress https://github.com/ourorg/jenkins-library.git +refs/heads/*:refs/remotes/origin/*
      > git config remote.origin1.url https://github.com/ourorg/jenkins-library.git # timeout=10
      Fetching upstream changes from https://github.com/ourorg/jenkins-library.git
      using GIT_ASKPASS to set credentials GitHub Access Token - ********
      > git fetch --tags --progress https://github.com/ourorg/jenkins-library.git +refs/pull/*/head:refs/remotes/origin/pr/*
      Checking out Revision 2527f5cd5e00ec77f9a833fe49db5e4d28327f5e (origin/pr/42)
      Commit message: "Ensure we use the devel images for CI"
      > git config core.sparsecheckout # timeout=10
      > git checkout -f 2527f5cd5e00ec77f9a833fe49db5e4d28327f5e
      > git rev-list 2527f5cd5e00ec77f9a833fe49db5e4d28327f5e # timeout=10
      

      After upgrading to 2.2.2, we now see this instead:

      Branch indexing
      13:18:12 Connecting to https://api.github.com using ********/****** (GitHub Access Token - ********)
      Obtained Jenkinsfile from 2527f5cd5e00ec77f9a833fe49db5e4d28327f5e
      [Pipeline] library
      Loading library kubic-jenkins-library@origin/pr/46
      > git rev-parse --is-inside-work-tree # timeout=10
      Setting origin to https://github.com/ourorg/jenkins-library.git
      > git config remote.origin.url https://github.com/ourorg/jenkins-library.git # timeout=10
      Fetching origin...
      Fetching upstream changes from origin
      > git --version # timeout=10
      using GIT_ASKPASS to set credentials GitHub Access Token - ********
      > git fetch --tags --progress origin +refs/heads/*:refs/remotes/origin/*
      > git rev-parse origin/pr/46^{commit} # timeout=10
      > git rev-parse origin/origin/pr/46^{commit} # timeout=10
      Command "git rev-parse origin/pr/46^{commit}" returned status code 128:
      stdout: origin/pr/46^{commit}
      
      stderr: fatal: ambiguous argument 'origin/pr/46^{commit}': unknown revision or path not in the working tree.
      Use '--' to separate paths from revisions, like this:
      'git <command> [<revision>...] -- [<file>...]'
      
      Command "git rev-parse origin/origin/pr/46^{commit}" returned status code 128:
      stdout: origin/origin/pr/46^{commit}
      
      stderr: fatal: ambiguous argument 'origin/origin/pr/46^{commit}': unknown revision or path not in the working tree.
      Use '--' to separate paths from revisions, like this:
      'git <command> [<revision>...] -- [<file>...]'
      
      [Pipeline] End of Pipeline
      
      GitHub has been notified of this commit?s build result
      
      ERROR: No version origin/pr/46 found for library kubic-jenkins-library
      Finished: FAILURE

      Looking for the difference, I see the pull refspec is now gone (+refs/pull//head:refs/remotes/origin/pr/)

      So, I went ahead and added the refspec back into the configuration manually, resulting in some progress, but it's still not quite working:

      Started by user Kiall Mac Innes
      13:41:53 Connecting to https://api.github.com using ********/****** (GitHub Access Token - ********)
      Obtained Jenkinsfile from 2527f5cd5e00ec77f9a833fe49db5e4d28327f5e
      [Pipeline] library
      Loading library kubic-jenkins-library@pull/46/head
      > git rev-parse --is-inside-work-tree # timeout=10
      Setting origin to https://github.com/ourorg/jenkins-library.git
      > git config remote.origin.url https://github.com/ourorg/jenkins-library.git # timeout=10
      Fetching origin...
      Fetching upstream changes from origin
      > git --version # timeout=10
      using GIT_ASKPASS to set credentials GitHub Access Token - ********
      > git fetch --tags --progress origin +refs/heads/*:refs/remotes/origin/* +refs/pull/*/head:refs/remotes/origin/pr/*
      > git rev-parse pull/46/head^{commit} # timeout=10
      > git rev-parse origin/pull/46/head^{commit} # timeout=10
      Cloning the remote Git repository
      Cloning with configured refspecs honoured and without tags
      Cloning repository https://github.com/ourorg/jenkins-library.git
      > git init /var/lib/jenkins/workspace/jenkins-library_PR-46-RIJ2ALPDMWBPWVY4GERXXJ2J2DLLAZPAQCYO7O7YSVFXRJR7FF3Q@libs/kubic-jenkins-library # timeout=10
      Fetching upstream changes from https://github.com/ourorg/jenkins-library.git
      > git --version # timeout=10
      using GIT_ASKPASS to set credentials GitHub Access Token - ********
      > git fetch --no-tags --progress https://github.com/ourorg/jenkins-library.git +refs/heads/pull/46/head:refs/remotes/origin/pull/46/head +refs/heads/*:refs/remotes/origin/* +refs/pull/*/head:refs/remotes/origin/pr/*
      ERROR: Error cloning remote repo 'origin'
      hudson.plugins.git.GitException: Command "git fetch --no-tags --progress https://github.com/ourorg/jenkins-library.git +refs/heads/pull/46/head:refs/remotes/origin/pull/46/head +refs/heads/*:refs/remotes/origin/* +refs/pull/*/head:refs/remotes/origin/pr/*" returned status code 128:
      stdout: 
      stderr: fatal: Couldn't find remote ref refs/heads/pull/46/head

      In this case, we now attempt to fetch:

      refs/heads/pull/46/head

      instead of:

      refs/pull/46/head

      I suspect the issue is here: https://github.com/jenkinsci/github-branch-source-plugin/blob/9672c85/src/main/java/org/jenkinsci/plugins/github_branch_source/GitHubSCMBuilder.java#L116-L124

       

            Unassigned Unassigned
            kiall kiall
            Votes:
            0 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated:
              Resolved: