What am I trying to accomplish is the following Jenkins (http://jenkins-ci.org) job configuration:
Have a set of <project>-master
jobs there are triggered by
I have accomplished this by specifying appropriate refspec, added the GitHub webhook, etc. It was pretty much straightforward.
Have a set of <project>-pr
jobs there are triggered by
I have made Jenkins do the first two. But I found no way to do the #3 item from this list because GitHub plugins can't easily find whether the push is to a PR branch or not. Any ideas how this can be done?
Have a set of <project>-branch
jobs that are triggered by ANY push to ANY branch. Problem is that I want to exclude pushes to master and to branches that are used for PRs. I've looked on the Internet for possible solution for days and came up with nothing, so any hint will be greatly appreciated.
Click the Settings tab. In the navigation pane, click Hooks. Click Add Webhook. In the Payload URL field, paste the webhook URL that you copied in Registering and configuring the GitHub repository.
Webhooks allow you to build or set up integrations, such as GitHub Apps or OAuth Apps, which subscribe to certain events on GitHub.com. When one of those events is triggered, we'll send a HTTP POST payload to the webhook's configured URL.
Secret. Setting a webhook secret allows you to ensure that POST requests sent to the payload URL are from GitHub. When you set a secret, you'll receive the X-Hub-Signature and X-Hub-Signature-256 headers in the webhook POST request.
Setting up a job to use the Github PUll Request Builder plugin as recommend, it will only trigger for a PR, for the 3 conditions you listed.
the more difficult one.. As far as I know, there is no easy way for jenkins to know whether a branch has a pull request or not, as pull requests are specific to github, and jenkins branch detection is just using git.
However, from my experience, for this third option, I've setup a <project>-feature
job, and configured it to match any branch prefixed with a f/
. This way, if a developer wanted tests to automatically execute against their branch, but did not want to open a pull request against it, they could create there branch like f/add_a_thing
, and it will automatically trigger tests on pushes. For this to work, I would set the branch specifier to f/*
in the job configuration.
Alternatively, the git plugin allows for a regular expression parameter to the branch specifier. You can use a regular expression to specifically ignore the master branch. However the only way to ignore pull requested branches, is by having your developers to use a naming pattern, such as pr/add_a_thing
, to identify that this branch will have a pull request with it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With