ambikanair
ambikanair

Reputation: 4590

Trigger jenkins build when PR is raised

I have gone through numerous post on triggering Jenkins build when a PR is raised in github.

I have checked Git hub Pull Request Builder Option in jenkins job and also provided ${sha1} as branch. Apart from above , I have added webhook and jenkins Github plugin as service in my repo.

Anything else being missed here . I dont see build getting triggered when PR is raised.

Upvotes: 1

Views: 1897

Answers (1)

Tomas Bjerre
Tomas Bjerre

Reputation: 3500

You can use Generic Webhook Trigger Plugin to do that.

Setup a webhook in GitHub. enter image description here

Configure Generic Webhook Trigger Plugin with variable action with expression $.action

Configure the filter text as $action and the filter regexp as: ^(opened|reopened|synchronize)$

Now this job will run any time a PR is opened, re-opened or new commits are pushed.

You can also pick other values from the webhook like:

  | variable        | expression                       | expressionType  | defaultValue | regexpFilter  |
  | action          | $.action                         | JSONPath        |              |               |
  | pr_id           | $.pull_request.id                | JSONPath        |              |               |
  | pr_state        | $.pull_request.state             | JSONPath        |              |               |
  | pr_title        | $.pull_request.title             | JSONPath        |              |               |
  | pr_from_ref     | $.pull_request.head.ref          | JSONPath        |              |               |
  | pr_from_sha     | $.pull_request.head.sha          | JSONPath        |              |               |
  | pr_from_git_url | $.pull_request.head.repo.git_url | JSONPath        |              |               |
  | pr_to_ref       | $.pull_request.base.ref          | JSONPath        |              |               |
  | pr_to_sha       | $.pull_request.base.sha          | JSONPath        |              |               |
  | pr_to_git_url   | $.pull_request.base.repo.git_url | JSONPath        |              |               |
  | repo_git_url    | $.repository.git_url             | JSONPath        |              |               |

There is a test case showing this feature here: https://github.com/jenkinsci/generic-webhook-trigger-plugin/blob/master/src/test/resources/org/jenkinsci/plugins/gwt/bdd/github/github-pull-request.feature

Upvotes: 3

Related Questions