PR引发时触发jenkins构建

时间:2018-04-11 05:57:03

标签: github jenkins-plugins webhooks pull-request

当在github中引发PR时,我已经经历了许多关于触发Jenkins构建的帖子。

我在jenkins工作中检查了Git hub Pull Request Builder选项,并提供了${sha1}作为分支。 除此之外,我在我的回购中添加了webhook和jenkins Github插件作为服务。

此处还有其他任何错误。当PR被提升时,我没有看到构建被触发。

1 个答案:

答案 0 :(得分:2)

您可以使用Generic Webhook Trigger Plugin来做到这一点。

在GitHub中设置一个Webhook。 enter image description here

为变量{strong> action 配置Generic Webhook Trigger Plugin,表达式为 $。action

将过滤器文本配置为 $ action ,将过滤器正则表达式配置为: ^(已打开|重新打开|同步)$

现在,此任务将在PR打开,重新打开或推送新的提交时运行。

您还可以从网络挂钩中选择其他值,例如:

  | 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        |              |               |

这里有一个测试案例展示了此功能:https://github.com/jenkinsci/generic-webhook-trigger-plugin/blob/master/src/test/resources/org/jenkinsci/plugins/gwt/bdd/github/github-pull-request.feature

相关问题