繁体   English   中英

BitBucket WebHook Jenkins

[英]BitBucket WebHook Jenkins

我想配置 bitbutcket 以触发 jenkins 构建。

我花了一些时间对此进行研究,所有答案都是几年前的,并且没有找到任何指南,因为从那以后情况似乎发生了变化。

我正在尝试做的事情: bitbucket 推送到特定分支会触发构建。

我得到了什么: Bitbucket web 钩子触发 HTTP 请求到 Z2E54334C0A5CE2E3E3E5A5845DF3 任何分支我还在 Jenkins 上安装了 Bitbucket 插件, Build when a change is pushed to BitBucket中添加了一个复选框。 尽管我推送到 SCM 部分中配置的分支,但此复选框似乎不起作用(也许我设置错了?为此的最少文档)。

问题 1 :Bitbucket 没有触发 GET,而是另一个导致 403 的请求。我用 postman 进行了测试,它适用于 GET,但不适用于 POST。

问题 2:这个 HTTP 构建请求在推送到任何分支时被触发。 虽然构建仍然仅限于特定分支,但似乎没有必要一直在重建。

我该如何解决这些问题? Bitbucket 在定制这个方面似乎不是很灵活。 bitbucket 的 Jenkins 插件有很多“差”评论。 开发人员目前是如何做到这一点的?

针对Jenkins CI服务器的特定解决方案 - 在Jenb for Bitbucket插件的Webhook已经在最新版本的Bit-Bucket中商业化,目前价格约为4800美元,这是早期的免费产品,因此,想要节省他们的钱,可以使用bit-bucket的webhooks功能转到替代解决方案: -

创建webhook的步骤: -

BitBucket Side

1)转到你的bitbucket repo,点击Repository Setting,在WORKFLOW下获取WEBHOOKS选项并创建一个webhook。

a)创建webhook: - URL https://JenkinsserverURL/git/notifyCommit?url=https://bitbucket.repository-link/repository.git

b)在名称选项卡中,提供您选择的任何名称

c)在保存之前单击TEST CONNECTION。 确保您获得http状态200 d)查看日志详细信息,检查您的请求和响应是否正确。

Jenkins Side要照顾的事情: -

1)确保在Jenkins作业中使用bitbucket webhook中提到的存储库。 2)在SCM选项中,激活/选择Poll SCM选项,不要在时间表中提及任何内容,将其留空。 3)配置休息工作,

每当你的git repo观察到任何变化时,都会在Jenkins中触发自动构建。 默认情况下,激活推送触发器,如果​​要激活其他操作,请在创建webhook时选择这些事件。

***在存储库webhook中指定分支: -

http://yourserver/git/notifyCommit?url=<URL of the Git repository>[&branches=branch1[,branch2]*][&sha1=<commit ID>]

干杯,

您的bitbucket服务器是否可以访问您的Jenkins URL? 如果是的话,它应该相当简单。 您将存储库中的webhook添加为http://<url-of-jenkins>/git/notifyCommit?url=<url-of-repository> 当jenkins收到此POST时,它会自动触发那些使用此git repo的作业的构建版本与您在webhook中提供的URL。
但是,您还需要确保将这些作业的“ Build Schedule设置为空。 否则它不会被触发。 您也可以在webhook URL中指定分支
请在此处查看Push Notification from repositoryPush Notification from repository
https://wiki.jenkins.io/display/JENKINS/Git+Plugin

对于 2022 年 7 月之后在这里的任何人,以下是我为使其工作而遵循的简单步骤。

创建直播 Jenkins URL

First, create a tunnel from a live URL to your local Jenkins URL using ngrok because using locahost:8080 directly as your webhook URL on bitbucket will simply not work as bitbucket does not recognize your local computer.

ps: ngrok claims to be the fastest way to put anything on the internet and I agree,
you can use it beyond Jenkins once you know the trick, 
such as quickly handling out your localhost react app for testing by your friends 
out of your local network

要做到这一点很简单。 对于 Linux:

  1. 安装 ngrok snap install ngrok
  2. 添加 authtoken ngrok config add-authtoken <token>

没有身份验证令牌,请注册

  1. 在您的 Jenkins 端口上启动隧道,例如ngrok http 8080

要了解更多信息和其他操作系统,请查看ngrok 下载页面

然后你会得到一个回应

ngrok                                                                                                                                                                                              (Ctrl+C to quit)
                                                                                                                                                                                                                   
Hello World! https://ngrok.com/next-generation                                                                                                                                                                     
                                                                                                                                                                                                                   
Session Status                online                                                                                                                                                                               
Account                       <your email>@<domain>.com (Plan: <plan type>)                                                                                                                                              
Version                       3.0.6                                                                                                                                                                                
Region                        Europe (eu)                                                                                                                                                                          
Latency                       162ms                                                                                                                                                                                
Web Interface                 <web interface url>
Forwarding                    https://<your-assigned-host>.ngrok.io -> http://localhost:8080                                       

Basically, the web interface URL on click gives you a web interface to inspect all the requests being tunnelled from your ngrok live URL to your local host.

Forwarding URL is basically a proxy to your localhost, so when you want to configure webhook, instead of using locahost:8080, you replace it with ngrok URL eg https://syue-162-34-12-01.eu.ngrok.io并且所有请求都通过隧道传输到 localhost:8080

在 bitbucket 云上连接 URL

Secondly, configure your Bitbucket repository with a Webhook, using URL JENKINS_URL/bitbucket-hook/ (no need for credentials but do remember the trailing slash) eg https://syue-162-34-12-01.eu.ngrok.io/bitbucket-hook/

If you are using bitbucket server and not cloud or you want to know more, the bitbucket plugin documentation for Jenkins is pretty straightforward and easily understandable, see bitbucket plugin

then you can inspect all your webhook requests on the web interface URL or via your terminal as well as check your build logs on Jenkins via your localhost port or ngrok live url.

免责声明:我还没有弄清楚如何仅在特定分支更改时启用构建,但您可以将 jenkins 配置为仅构建特定分支或根据您的需要创建的任何分支,检查源代码管理构建触发器

暂无
暂无

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

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