Need Github pull request number as environment variable

245 views
Skip to first unread message

Cody Ebberson

unread,
May 25, 2017, 8:37:20 PM5/25/17
to Jenkins Users
Hello,

I'm configuring Github + Jenkins + Sonar.  Almost everything is working, and I am incredibly pleased (great job!)  I'm now struggling with one missing piece which seems like it should be simple.

The last piece I need is the Github pull request *number* as an environment variable to pass to Sonar for "preview" mode analysis.

Here are the relevant components and versions:

Jenkins version 2.46.3
Jenkins "GitHub Branch Source Plugin" version 2.0.5
Maven version 3.3.9
Maven Sonar plugin version 3.3.0.603
Sonar version  6.3.1.21392
Sonar Github plugin version 1.4.1

Per https://stackoverflow.com/a/32095346 it looks like the old "GitHub Pull Request Builder" plugin added a ${ghprbPullId} environment variable.  That environment variable is not set by the "GitHub Branch Source Plugin" (as far as I can tell).

A dump of "env" does not show anything about pull requests, change ID's, etc.  The known pull request number is not anywhere in the logs.

Suggestions?

If this isn't available through Jenkins, I think we could do some curl + Github API magic to search for the Pull Request number, but that obviously seems suboptimal.

Thanks in advance!

Cody

Cody Ebberson

unread,
May 26, 2017, 11:47:57 AM5/26/17
to Jenkins Users
I went ahead with a script to search for the Pull Request number.  Here is the script in case anyone might find it useful:

Joshua Noble

unread,
May 28, 2017, 12:50:31 PM5/28/17
to Jenkins Users
If you use the GitHub branch source plugin, the pull request number will show up in the $BRANCH variable. I suggest using this plugin as it will automatically create jobs and build every branch and PR.

Arvind Jayaprakash

unread,
May 30, 2017, 9:46:35 AM5/30/17
to Jenkins Users
The environment variable CHANGE_ID contains the PR number

Paper Arts Calif

unread,
Jul 19, 2017, 1:18:29 AM7/19/17
to Jenkins Users
It doesn't. :-( Not in the latest version of the plugin.
Reply all
Reply to author
Forward
0 new messages