如何使用Github Webhook在Jenkins中触发管道

时间:2017-09-18 13:27:04

标签: jenkins triggers jenkins-plugins jenkins-pipeline webhooks

我想用Github webhook触发一个管道。此管道与我的Github存储库和Github webhook连接。

我想用webhook中的信息作为ID_commit,Github分支或其他东西触发此管道。

例如:if BRANCH == master : Build Pipeline

我尝试使用2个插件,但它不起作用:

1 个答案:

答案 0 :(得分:0)

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.