Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jenkins integrating with Github Organization: on opened pull requests, only run build for pull request NOT for branches

I am currently using Jenkins CI with Github webhooks. I set up a view for my Github Organization. Jenkins is able to scan my organization for branches and pull requests and run builds on pull requests with Jenkinsfiles. This current discovery functionality is okay. However, when a new pull request gets opened on a repo, a build is run for both the branch, and the pull request. These are being done in separate workspaces as well. So in github, I see builds for continuous-integration/jenkins/branch and continuous-integration/jenkins/pr-merge. I would only like to run the build for the pr-merge and not for branch. I can't seem to find any configuration options in Jenkins to tweak this.

It seems that I am looking for options specified in the Github Branch Source Plugin in this section. I have confirmed that the plugin is installed, but I can't find a way to modify these settings anywhere, neither in the GUI, nor $JENKINS_HOME.

Any help on how to do this would be much appreciated. There's really no benefit for us to have a build log of all branches being used for pull requests, since they are later discarded.

like image 963
Scott Davidson Avatar asked Jan 31 '18 16:01

Scott Davidson


People also ask

How can we make Jenkins pipeline jobs triggered by pull requests?

Configure your pipelineOn the Datalog Tagging tab, check “GitHub project”, and put your project URL in the field. On the Build Triggers tab, check “GitHub Pull Request Builder”. Then the GitHub API credentials is automatically filled in. Make sure the Admin list is filled in with at least one admin name.

How do pull requests work GitHub?

Pull requests let you tell others about changes you've pushed to a branch in a repository on GitHub. Once a pull request is opened, you can discuss and review the potential changes with collaborators and add follow-up commits before your changes are merged into the base branch.


3 Answers

If you add Filter by name (with regular expression) to Behaviours as develop|PR-.* it will stop triggering the pipeline for branches that doesn't match the pattern. screenshot

like image 68
Tiko Lakin Avatar answered Oct 20 '22 01:10

Tiko Lakin


You can change the Discover branches strategy to exclude branches that are also filed as pull request:

enter image description here

like image 36
StephenKing Avatar answered Oct 19 '22 23:10

StephenKing


Discover Branches: Exclude branches that are also filed as PRs

See Controlling what is built section on the documentation page for the Github Branch Source plugin page. https://go.cloudbees.com/docs/cloudbees-documentation/cje-user-guide/index.html#github-branch-source

Would also suggest if you have your GitHub repository configured for status checks you disable the branch status' that was generated so your PR only depends on the PR status. See GitHub doc: https://help.github.com/articles/enabling-required-status-checks/

like image 34
Bradley C. Herrin Avatar answered Oct 20 '22 00:10

Bradley C. Herrin