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.