ghprb
ghprb copied to clipboard
NPE when trying to use upstream status in build that does not have GHPRB trigger
Relevant build log error:
Nov 12, 2015 2:35:52 PM org.jenkinsci.plugins.ghprb.upstream.GhprbUpstreamStatusListener updateEnvironmentVars
SEVERE: Unable to connect to GitHub repo
java.lang.NullPointerException
at org.kohsuke.github.GitHub.getRepository(GitHub.java:322)
at org.jenkinsci.plugins.ghprb.upstream.GhprbUpstreamStatusListener.updateEnvironmentVars(GhprbUpstreamStatusListener.java:76)
at org.jenkinsci.plugins.ghprb.upstream.GhprbUpstreamStatusListener.onCompleted(GhprbUpstreamStatusListener.java:117)
at org.jenkinsci.plugins.ghprb.upstream.GhprbUpstreamStatusListener.onCompleted(GhprbUpstreamStatusListener.java:34)
at hudson.model.listeners.RunListener.fireCompleted(RunListener.java:201)
at hudson.model.Run.execute(Run.java:1783)
at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
at hudson.model.ResourceController.execute(ResourceController.java:98)
at hudson.model.Executor.run(Executor.java:410)
Relevant env variables:
ghprbCommitStatusContext tests
ghprbUpstreamStatus true
This appears to break because it's expecting the ghprbGhRepository variable but that was only set on the upstream job since the downstream job wasn't triggered by ghprb. I was able to get something that kinda works by using the Parametrized Trigger plugin to set the build parameters for the downstream build the same as the upstream build, but it still throws a couple funny errors, probably because it's missing Cause and Trigger information. It's good enough for what I am trying to do with it, but I wanted to let you know that this seems to be broken. You're going to need to actually look up all this info in the actual upstream job because the downstream job isn't guaranteed to actually be triggered by a pull request. You may even have to walk up the tree of jobs until you find one that was triggered that way, because users might want to nest more than one level of job on the PR.
I seem to get this problem as well. The cause of the problem is quite similar to what @dwightguth mentioned in the above post. The environment variables are not seen in the downstream jobs when the build is finished and trying to post the commit status. I've boiled down to ghprbGhRepository
, ghprbPullId
, and ghprbActualCommit
. The first envVar is coming from GhprbUpstreamStatusListener
and the latter two envVars are coming from GhprbSimpleStatus
when build completes.
My solution is to also use Parameterized Trigger plugin and add the following parameters to "Predefined Parameters" in the upstream jobs so that the envVars are passed into the downstream jobs. This will ensure that the commit statuses are posted in the PR.
ghprbGhRepository=${ghprbGhRepository}
ghprbPullId=${ghprbPullId}
ghprbActualCommit=${ghprbActualCommit}
This solution is a hack temporarily. A long term solution is needed by modifying the Ghprb code. Can @DavidTanner please shed some light about what code needs to be changed for this problem?
Thanks @Eriten for the hack.. I was stuck with this problem as well.