【问题标题】:Trigger jenkins build when PR is raised提高 PR 时触发 jenkins 构建
【发布时间】:2018-09-20 21:25:29
【问题描述】:

我已经阅读了很多关于在 github 中提出 PR 时触发 Jenkins 构建的帖子。

我已经检查了 jenkins 工作中的 Git hub Pull Request Builder 选项,并且还提供了 ${sha1} 作为分支。 除了上述之外,我还在我的仓库中添加了 webhook 和 jenkins Github 插件作为服务。

这里还有什么遗漏的。当 PR 被提升时,我没有看到构建被触发。

【问题讨论】:

  • 你忘了说你要做什么。
  • 我已经提到“当 PR 被提升时触发 jenkins 构建”。这个声明很清楚我在寻找什么“当 PR 被提升时,我没有看到构建被触发”@BooberBunz Bunz

标签: github jenkins-plugins webhooks pull-request


【解决方案1】:

您可以使用Generic Webhook Trigger Plugin 来执行此操作。

在 GitHub 中设置 webhook。

使用表达式 $.action

使用变量 action 配置 Generic Webhook Trigger Plugin

将过滤器文本配置为 $action 并将过滤器正则表达式配置为:^(opened|reopened|synchronize)$

现在该作业将在 PR 打开、重新打开或推送新提交时运行。

您还可以从 webhook 中选择其他值,例如:

  | 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

【讨论】:

    猜你喜欢
    • 2023-03-27
    • 1970-01-01
    • 2021-09-19
    • 2022-10-06
    • 2015-09-25
    • 1970-01-01
    • 1970-01-01
    • 2020-07-02
    • 1970-01-01
    相关资源
    最近更新 更多