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

Cannot merge PRs from private, forked repositories

XMLWordPrintable

      When using bitbucket-branch-source-plugin (versions 2.2.1 and 2.2.3 tested so far), with the project option "Discover pull requests from forks" > "Merging the pull request with the current target branch revision" selected, using Git as the SCM source, when the source branch of the PR is a private forked repository, builds fail at the SCM checkout stage with the error message fatal: Couldn't find remote ref refs/heads/upstream-master. E.g.:

      Checking out git ssh://git@my.bitbucket.server:7999/SC/cub_test.git ssh://git@my.bitbucket.server:7999/SC/cub_test.git to read Jenkinsfile
      Cloning the remote Git repository
      Cloning with configured refspecs honoured and without tags
      Cloning repository ssh://git@my.bitbucket.server:7999/SC/cub_test.git
       > git init /var/lib/jenkins/workspace/on_management_cub_test_PR-4-ES4EOS7LPI5QNDQYMSQBQYLUVFG67RVT46H7N3NKYA4MAXRN5SOQ@script # timeout=10
      Fetching upstream changes from ssh://git@my.bitbucket.server:7999/SC/cub_test.git
       > git --version # timeout=10
      using GIT_SSH to set credentials Credentials for jenkins - created by Chef
       > git fetch --no-tags --progress ssh://git@my.bitbucket.server:7999/SC/cub_test.git +refs/pull-requests/4/from:refs/remotes/origin/PR-4
       > git config remote.origin.url ssh://git@my.bitbucket.server:7999/SC/cub_test.git # timeout=10
       > git config --add remote.origin.fetch +refs/pull-requests/4/from:refs/remotes/origin/PR-4 # timeout=10
       > git config remote.origin.url ssh://git@my.bitbucket.server:7999/SC/cub_test.git # timeout=10
      Cleaning workspace
       > git rev-parse --verify HEAD # timeout=10
      No valid HEAD. Skipping the resetting
       > git clean -fdx # timeout=10
      Fetching without tags
      Fetching upstream changes from ssh://git@my.bitbucket.server:7999/SC/cub_test.git
      using GIT_SSH to set credentials Credentials for jenkins - created by Chef
       > git fetch --no-tags --progress ssh://git@my.bitbucket.server:7999/SC/cub_test.git +refs/pull-requests/4/from:refs/remotes/origin/PR-4
       > git config remote.upstream.url ssh://git@my.bitbucket.server:7999/SC/cub_test.git # timeout=10
      Cleaning workspace
       > git rev-parse --verify HEAD # timeout=10
      No valid HEAD. Skipping the resetting
       > git clean -fdx # timeout=10
      Fetching without tags
      Fetching upstream changes from ssh://git@my.bitbucket.server:7999/SC/cub_test.git
      using GIT_SSH to set credentials Credentials for jenkins - created by Chef
       > git fetch --no-tags --progress ssh://git@my.bitbucket.server:7999/SC/cub_test.git +refs/heads/upstream-master:refs/remotes/upstream/master
      ERROR: Error fetching remote repo 'upstream'
      hudson.plugins.git.GitException: Failed to fetch from ssh://git@my.bitbucket.server:7999/SC/cub_test.git
      	at hudson.plugins.git.GitSCM.fetchFrom(GitSCM.java:817)
      	at hudson.plugins.git.GitSCM.retrieveChanges(GitSCM.java:1084)
      	at hudson.plugins.git.GitSCM.checkout(GitSCM.java:1115)
      	at org.jenkinsci.plugins.workflow.steps.scm.SCMStep.checkout(SCMStep.java:113)
      	at org.jenkinsci.plugins.workflow.cps.CpsScmFlowDefinition.create(CpsScmFlowDefinition.java:130)
      	at org.jenkinsci.plugins.workflow.multibranch.SCMBinder.create(SCMBinder.java:120)
      	at org.jenkinsci.plugins.workflow.job.WorkflowRun.run(WorkflowRun.java:262)
      	at hudson.model.ResourceController.execute(ResourceController.java:97)
      	at hudson.model.Executor.run(Executor.java:405)
      Caused by: hudson.plugins.git.GitException: Command "git fetch --no-tags --progress ssh://git@my.bitbucket.server:7999/SC/cub_test.git +refs/heads/upstream-master:refs/remotes/upstream/master" returned status code 128:
      stdout: 
      stderr: fatal: Couldn't find remote ref refs/heads/upstream-master
      
      	at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:1903)
      	at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandWithCredentials(CliGitAPIImpl.java:1622)
      	at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.access$300(CliGitAPIImpl.java:71)
      	at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$1.execute(CliGitAPIImpl.java:348)
      	at hudson.plugins.git.GitSCM.fetchFrom(GitSCM.java:815)
      	... 8 more
      [Bitbucket] Notifying pull request build result
      [Bitbucket] Build result notified
      ERROR: Error fetching remote repo 'upstream'
      Finished: FAILURE
      

      It appears to me, based on the output of git ls-remote --refs, that the remote ref that should be fetched instead is refs/pull-requests/4/merge:

      [birdsnest ~/local/tmp/test1/cub_test](master|✔)[I]% git ls-remote --refs
      X11 forwarding request failed on channel 0
      From ssh://git@my.bitbucket.server:7999/SC/cub_test.git
      fc70c3425adca15bd2b717665d463f93c845eae3	refs/heads/foo
      909003cd843aefae502b53a7ff22325bc76d095d	refs/heads/master
      8453ccb061f0bf98ae2dc39f31b8b3c13e5d8bd8	refs/heads/test
      87a9a0e7ffae90e7264dfb31d05e9abb224a6e0a	refs/heads/test1
      d45b0b5e8217bf51bdbba2f6bbc8b61d83ee4405	refs/pull-requests/4/from
      0f54d475c62c21f579cddd0650b2c0db575a4304	refs/pull-requests/4/merge
      87a9a0e7ffae90e7264dfb31d05e9abb224a6e0a	refs/pull-requests/5/from
      

            stephenconnolly Stephen Connolly
            jay_hendren jay hendren
            Votes:
            5 Vote for this issue
            Watchers:
            9 Start watching this issue

              Created:
              Updated:
              Resolved: