0
votes

I have a job in CloudBees setup to

Build pull requests to the repository

It works fine but what I really need is to be able to get the pull request number that triggered the build for use in the execute shell commands field. I know for sure CloudBees/Jenkins is aware of it because the very first line it prints in the Console Output is

GitHub pull request #4 to owner/repo

But I haven't been able to find a way to easily get access to that #4. I can't find where the console log is stored and it doesn't appear to be an environment variable either. I tried doing an "env" in the execute shell commands field and it wasn't anywhere in there.

How can I get the pull request number from CloudBees/Jenkins for use in the execute shell commands field?

3

3 Answers

1
votes

1.0-beta-3, just released to the update center, defines $GIT_PR_NUMBER (among other variables) for this purpose.

1
votes

I do not see a good way currently. You can try

PR=$(curl -s "${BUILD_URL}api/xml?tree=description" | perl -n -e 'print("$1\n") if m{pull/(\d+)"}')
-1
votes

Assuming you're using CloudBees github pull request tester plugin, you can retrieve the pull request number from the build cause (com.cloudbees.jenkins.plugins.github_pull.GitHubPullRequestCause#number)