How to trigger pipeline in Jenkins with Github Webhook

Viewed 1558

I would like to triggered one pipeline with Github webhook. This pipeline is connected with my Github Repository and a Github webhook.

I want to trigger this pipeline with informations in the webhook as the ID_commit, Github branch, or other things.

For example : if BRANCH == master : Build Pipeline

I try to use 2 plugins but it doesn't works :

1 Answers

The webhook being sent from GitHub on push looks like this: https://developer.github.com/v3/activity/events/types/#pushevent

...
{
  "ref": "refs/heads/changes",
  "before": "9049f1265b7d61be4a8904a9a27120d2064dab3b",
  "after": "0d1a26e67d8f5eaf1f6ba5c57fc3c7d91ac0fd1c",
  "created": false,
...

To get the branch (ref) into a variable you need to configure a JSONPath parameter. Like maby variable ref and expression $.ref

To trigger only if branch is master you need to configure a filter. In Optional filter, specify regexp as master and text as $ref

Also, as the wiki suggests, troubleshooting this with curl is probably easiest.

Related