ghprb icon indicating copy to clipboard operation
ghprb copied to clipboard

ghprb doesn't appear to be getting any pull requests during polling

Open chrisst opened this issue 8 years ago • 4 comments

I'm trying to set up a build but polling doesn't seem to be finding any of the PR's. So I checked in the polling log for the build and noticed it's finding the branches (and correctly ignoring them) but none of the /pulls/ refs. The output is here:

using GIT_SSH to set credentials jenkins-build-node
using .gitcredentials to set credentials
 > git --version # timeout=10
 > git init /tmp/hudson7186305084432749189tmp # timeout=10
 > git config --local credential.username jenkins # timeout=10
 > git config --local credential.helper store --file=/tmp/git4586400477556766811.credentials # timeout=10
 > git -c core.askpass=true ls-remote -h https://github.com/blah/blah.git/ # timeout=10
 > git config --local --remove-section credential # timeout=10
Found 17 remote heads on https://github.com/blah/blah.git/
Ignoring refs/heads/cleaner-errors as it doesn't match any of the configured refspecs

I ran the ls-remote command (git -c core.askpass=true ls-remote -h https://github.com/blah/blah.git/ # timeout=10) locally to see what was coming back and noticed it was not pulling down any of the pulls. But if I remove the -h flag it actually lists the pulls as expected. I'm not sure why the pulls aren't showing up with the heads flag, but it results in no builds getting triggered.

Is there a way to configure jenkins to stop throwing the head flag into the polling mechanism or another work around?

for reference: refspec: +refs/pull/*:refs/remotes/origin/pr/* branch: ${sha1} I have tested from the global config and been able to comment, change status, etc.

chrisst avatar Jun 10 '16 18:06 chrisst

Same here. And I think this may be the same as #425.

In the log I am seeing a lot of these lines with every poll. If I have commented "Jenkins test this" in the PR, it acknowledges that in the second line below but doesn't start building.

Jun 21, 2016 6:57:01 PM org.jenkinsci.plugins.ghprb.GhprbPullRequest updatePR
INFO: Pull request #392 was updated/initialized on quaive/ploneintranet at 6/21/16 6:56 PM by Alessandro Pisa (PR update)
Jun 21, 2016 6:57:01 PM org.jenkinsci.plugins.ghprb.GhprbPullRequest updatePR
INFO: Pull request #392 was updated on repo quaive/ploneintranet but there aren't any new comments nor commits; that may mean that commit status was updated.
Jun 21, 2016 6:57:01 PM org.jenkinsci.plugins.ghprb.GhprbPullRequest updatePR
INFO: Pull request #391 was updated on repo quaive/ploneintranet but there aren't any new comments nor commits; that may mean that commit status was updated.

pilz avatar Jun 21 '16 17:06 pilz

I found the issue and will have a fix out for it in the next couple hours.

DavidTanner avatar Jun 21 '16 19:06 DavidTanner

What version will this fix be included in?

jerrellmardis avatar Jul 06 '16 21:07 jerrellmardis

Issue

To answer to @ThorArakis , I experienced the same issue (the logs are from the "GitHub Hook Log" in the left panel of the jenkin's job):

org.jenkinsci.plugins.gitclient; launchCommandWithCredentials@1347 using .gitcredentials to set credentials git --version # timeout=10 git init /tmp/hudson8014832060974631761tmp # timeout=10 git config --local credential.username eramox-jenkins # timeout=10 git config --local credential.helper store --file=/tmp/git243679553520720828.credentials # timeout=10 git -c core.askpass=true ls-remote -h https://github.com/EramoxPersonalWork/liberamox.git # timeout=10 git config --local --remove-section credential # timeout=10 Found 5 remote heads on https://github.com/EramoxPersonalWork/liberamox.git Ignoring refs/heads/gh-pages as it doesn't match any of the configured refspecs Ignoring refs/heads/feature/testGerrit as it doesn't match any of the configured refspecs Ignoring refs/heads/feature/Coverity_support as it doesn't match any of the configured refspecs Ignoring refs/heads/master as it doesn't match any of the configured refspecs Ignoring refs/heads/add_doc_link as it doesn't match any of the configured refspecs Done. Took 0.5 sec No changes

Cause

I tried to solve it trying to find the root cause (I obtained this stacktrace by luck, trying to fix the issue, and especially modifying the variable GIT_SSH wich make the call fail):

java.io.IOException: hudson.plugins.git.GitException: Command "git -c core.askpass=true         ls-remote -h [email protected]:EramoxPersonalWork/liberamox.git" returned status code 128:
stdout: 
stderr: error: cannot run GIT_SSH=/var/lib/openshift/579128dc89f5cf45630000cf/app-root      /data/compilation/git-ssh-wrapper/bin/myWrapper.sh: No such file or directory
fatal: unable to fork

at hudson.plugins.git.GitSCM.compareRemoteRevisionWith(GitSCM.java:576)
at hudson.scm.SCM.compareRemoteRevisionWith(SCM.java:381)
at hudson.scm.SCM.poll(SCM.java:398)
at hudson.model.AbstractProject._poll(AbstractProject.java:1453)
at hudson.model.AbstractProject.poll(AbstractProject.java:1356)
at com.cloudbees.jenkins.GitHubPushTrigger$1.runPolling(GitHubPushTrigger.java:88)
at com.cloudbees.jenkins.GitHubPushTrigger$1.run(GitHubPushTrigger.java:114)
at hudson.util.SequentialExecutionQueue$QueueEntry.run(SequentialExecutionQueue.java:119)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
Caused by: hudson.plugins.git.GitException: Command "git -c core.askpass=true ls-remote -h  [email protected]:EramoxPersonalWork/liberamox.git" returned status code 128:
stdout: 
stderr: error: cannot run GIT_SSH=/var/lib/openshift/579128dc89f5cf45630000cf/app-root  /data/compilation/git-ssh-wrapper/bin/myWrapper.sh: No such file or directory
fatal: unable to fork

at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:1723)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandWithCredentials(CliGitAPIImpl.java:1459)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandWithCredentials(CliGitAPIImpl.java:1345)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandWithCredentials(CliGitAPIImpl.java:1336)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.getHeadRev(CliGitAPIImpl.java:2454)
at hudson.plugins.git.GitSCM.compareRemoteRevisionWithImpl(GitSCM.java:615)
at hudson.plugins.git.GitSCM.compareRemoteRevisionWith(GitSCM.java:574)
... 12 more
Done. Took 0.29 sec
No changes

In this stacktrace, we can see some interessant details:

  • org.jenkinsci.plugins.gitclient.CliGitAPIImpl.getHeadRev: the function which will call "ls-remote" with the parameter "-h"
  • compareRemoteRevisionWith: the function which will match heads from getHeadRev and the one provided (in the field "branch to build" on the jenkins job configuration page)

In the case of the GitHub Pull Request Builder, the documentation recommend to use the regex "+refs/pull/:refs/remotes/origin/pr/" to match pull request URI. Unfortunately, ls-remote -h <...> used by getHeadRev will never returns this kind of URI.

An example of behavior with "-h":

$ git -c core.askpass=true ls-remote -h [email protected]:EramoxPersonalWork/liberamox.git
c549c        refs/heads/add_doc_link
4e2fd        refs/heads/feature/Coverity_support
47577        refs/heads/feature/testGerrit
9f485        refs/heads/gh-pages
1f68a        refs/heads/master

and without:

$ git -c core.askpass=true ls-remote [email protected]:EramoxPersonalWork/liberamox.git
c549c        refs/heads/add_doc_link
4e2fd        refs/heads/feature/Coverity_support
47577        refs/heads/feature/testGerrit
9f485        refs/heads/gh-pages
1f68a        refs/heads/master
f19b0        refs/changes/01/284201/1
bd17b        refs/pull/13/head <- The one we want !!

the issue comes from the plugins (they are correclty used, but they would need a new function in order to retrieve all refs instead of only the heads):

  • git-client-plugin
  • git-plugin

I tried to build a custom version to try but I couldn't hack those as I was unable to build them (far too many errors in eclipse when importing the project)

Solution

I couldn't find an easy solution so I falled back on a workaround:

  • don't fill the field "ref" > the plugin doesn't use "-h" to list the branch so it sees all of them
  • checkout the branch to build in the script to run:
    • git clone
    • cd in the repo directory
    • git fetch origin
    • GIT_BRANCH=${GIT_BRANCH#*/} (the variable GIT_BRANCH has the format origin/ so we are ditching everything until the slash)
    • git checkout -b $GIT_BRANCH origin/$GIT_BRANCH ()
    • git merge master (step to check that the commit is mergeable, master can be replaced by the correct branch depending on project)

It is far from a perfect solution but its the best I could find to make it work for my current setup.

eramox avatar Jul 23 '16 20:07 eramox