Access GitHub Pull Request Number from within Jenkinsfile? (in the refactored Multibranch Pipeline plugin)

1,654 views
Skip to first unread message

Paper Arts Calif

unread,
Jul 19, 2017, 1:18:29 AM7/19/17
to Jenkins Users
Hello,
I am trying to access the Pull Request Number from within my Jenkinsfile, so that my Multibranch Pipeline build can do interesting stuff with it (like post a comment to the PR). Unfortunately, although the documentation claims this is available in CHANGE_ID, I have not found this to be the case. I am running the newly refactored Multibranch Pipeline plugin.

Jenkins base version: 2.60.1
Pipeline:Multibranch plugin version: 2.16

My Jenkinsfile contains this code:

            echo "CHANGE_ID is ${env.CHANGE_ID}"
            echo "PULL_REQUEST is ${env.PULL_REQUEST}"

My Multibranch Pipeline project detects when I have created a PR branch, and it automatically builds the PR branch.
However, the build output contains this:

[Pipeline] echo
CHANGE_ID is null
[Pipeline] echo
PULL_REQUEST is null

I found this Stack Overflow article 


which suggests I need to 
- Disable branch builds
- Enable PR builds
- Check a checkbox 'Build origin PRs (unmerged head)

^^ All of which appear to pertain to a January 2017 version (now deprecated) of the plugin.

Anyhow, as I said, my PR branch is being detected and built, but even dumping out 'env' did not show any env vars containing the PR number.

Stephen Connolly

unread,
Jul 19, 2017, 3:32:36 AM7/19/17
to jenkins...@googlegroups.com
https://github.com/jenkinsci/branch-api-plugin/blob/master/src/main/java/jenkins/branch/BranchNameContributor.java#L65 is the code.

Have you updated your github and/or bitbucket plugins to the versions that actually expose the ChangeRequestSCMHead2 interface?

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/bd781dee-fecb-426c-b618-e63a9e4512cd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages