Getting user who created a pull request with Jenkins pipeline

31 views
Skip to first unread message

Eberhard Beilharz

unread,
Oct 23, 2019, 11:44:38 AM10/23/19
to Jenkins Users
When using a Jenkins pipeline, how can I get the user who created a GitHub pull request? Or even better, how can I check if the user that opened the PR is an org member (or collaborator) or if this is an external PR?

We're using multibranch pipeline jobs to build the master branch and the PRs. Jenkins checks if this is a trusted PR and only applies changes to `Jenkinsfile` if they come for trusted users. However, I'd like to be able to prevent the build from happening automatically when the PR is not from a trusted user.

Thanks for any pointers!

Eberhard

Mark Waite

unread,
Oct 23, 2019, 11:59:14 AM10/23/19
to Jenkins Users
I thought that is the case that the GitHub branch source provides with the setting under "Discover pull requests from forks":

discover-pull-requests-from-forks.png

--
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-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/570f4ca5-5c27-42df-bd12-4969426d65e5%40googlegroups.com.


--
Thanks!
Mark Waite

Eberhard Beilharz

unread,
Oct 23, 2019, 9:24:56 PM10/23/19
to Jenkins Users
The help text that appears if you click on ? makes it sound as this applies only to `Jenkinsfile`.

On the other side, the heading "Discover pull requests from forks" sounds like it would apply to all pull requests, i.e. if I select "From users with Admin or Write permission" it wouldn't consider external ones. But that's not the behaviour I observe.

Anyways, what I want is to be able to distinguish inside of the build job between external PRs and PRs from members and collaborators. PRs from members and collaborators should be built automatically whereas  for external PRs I was thinking of using input to require manual confirmation before the rest of the build proceeds.

Eberhard Beilharz

unread,
Oct 24, 2019, 8:41:22 AM10/24/19
to Jenkins Users
Answering (part of) my own question: there's an environment variable CHANGE_AUTHOR that gets set on a PR. There's also the pipeline-github-plugin that provides information about a PR.

Now to figure out how to find out if the change author is a member/collaborator or not...
Reply all
Reply to author
Forward
0 new messages