简体   繁体   English

根据拉取请求从 Bitbucket 触发 Jenkins 作业

[英]Trigger Jenkins Job from Bitbucket on Pull Request

Hoping to gather insight from professionals.希望得到专业人士的意见。 My end goal is to trigger a jenkins build whenever a bitbucket pull request happens.我的最终目标是在发生bitbucket拉取请求时触发 jenkins 构建。 If anyone could give me an ELI5(explain like I am 5) answer it would be greatly appreciated.如果有人能给我一个 ELI5(像我 5 一样解释)答案,我将不胜感激。 Sorry if this is the wrong format, I am new to jenkins and stackoverflow.对不起,如果这是错误的格式,我是 jenkins 和 stackoverflow 的新手。

What I have done so far:到目前为止我做了什么:

  1. Created webhook in bitbucket and gave the url to my jenkins job.在 bitbucket 中创建了 webhook 并将 URL 提供给我的 jenkins 工作。 example: http://jenkinsURL:8080/job/boulevard-dev/generic-webhook-trigger/invoke?token=myPull_Request_Token例如: http://jenkinsURL:8080/job/boulevard-dev/generic-webhook-trigger/invoke?token=myPull_Request_Token

  2. Pull request webhook trigger拉取请求网络钩子触发器

  3. In Jenkins, under source code management I have: Source Code Management Settings .在 Jenkins 中,在源代码管理下我有: Source Code Management Settings This is currently fetching a ton of branches, failing, then building the master branch when the job starts?这当前正在获取大量分支,失败,然后在作业开始时构建主分支?

  4. For build triggers, other stackoverflow articles have pointed me to the "Generic Webhook Trigger".对于构建触发器,其他 stackoverflow 文章已将我指向“通用 Webhook 触发器”。 https://github.com/jenkinsci/generic-webhook-trigger-plugin https://github.com/jenkinsci/generic-webhook-trigger-plugin

  5. I am not entirely sure how this generic webhook trigger should effectively be setup?我不完全确定应该如何有效地设置这个通用的 webhook 触发器? Hoping someone has experience using it and could explain what is needed.希望有人有使用它的经验并可以解释需要什么。

  6. This is what have seen referenced in other articles.这是在其他文章中看到的引用。 Build Triggers settings Build triggers settings 2构建触发器设置构建触发器设置 2

Questions:问题:

  • What does a correct setup / example of the generic webhook trigger look like?通用 webhook 触发器的正确​​设置/示例是什么样的?
  • Currently, my job triggers when a change is made to master or merged to master, how can I specify to my job that I want the bitbucket pull request branch to be built?目前,当对 master 进行更改或合并到 master 时,我的工作会触发,我如何向我的工作指定我希望构建 bitbucket 拉取请求分支?
  • Also, I found this, not sure if its related to my issue or not?另外,我发现了这个,不确定它是否与我的问题有关? https://jira.atlassian.com/browse/BCLOUD-5814 https://jira.atlassian.com/browse/BCLOUD-5814

As per your requirement, you can trigger a Jenkins build whenever a bitbucket pull request happens by following the below steps, in my case, it's working fine.根据您的要求,您可以按照以下步骤在发生 bitbucket 拉取请求时触发 Jenkins 构建,在我的情况下,它工作正常。

Step(1) - Configure Jenkins步骤 (1) - 配置 Jenkins
(i) Add your bitBucket repo and branch to source code management (i) 将您的 bitBucket 存储库和分支添加到源代码管理在此处输入图片说明 (ii) On build Triggers setup Poll SCM to * * * * * for run every minute to check pull request from bitBucket. (ii) 在构建时触发设置 Poll SCM 到 * * * * * 以每分钟运行一次以检查来自 bitBucket 的拉取请求。 在此处输入图片说明

Step(2) - configure Bit Bucket Hook步骤 (2) - 配置 Bit Bucket Hook
(i) Go to settings and add a new hook, now setup pull request trigger as per your requirement. (i) 转到设置并添加一个新钩子,现在根据您的要求设置拉取请求触发器。 在此处输入图片说明

Step(3) - Make a pull request and see the new job automatically triggered on Jenkins.步骤 (3) - 发出拉取请求并查看在 Jenkins 上自动触发的新作业。 在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM