BitBucket WebHook Jenkins



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

我花了一些时间研究这个问题,所有答案都来自几年前,并且没有找到任何指南,因为此后情况似乎发生了变化。

我要做的事情:Bitbucket推到特定的分支会触发构建。

我有什么:Bitbucket Web挂钩将HTTP请求发射给Jenkins,以推向任何分支。我还在Jenkins上安装了Bitbucket插件,该插件在作业CONCON Build when a change is pushed to BitBucket中添加了复选框。此复选框似乎不起作用(也许我设置了错误?为此,最小文档),尽管我推到了SCM部分中的配置分支。

问题1 :bitbucket不会发射get,而是导致403的另一个请求。我与Postman进行了测试,它可以使用get,但不能使用帖子。

问题2:此HTTP构建请求被推送到任何分支。虽然构建仍然仅限于特定的分支,但似乎不必一直在重建。

如何解决这些问题?Bitbucket在自定义方面似乎并不是很灵活。Bitbucket的Jenkins插件有很多"不良"评论。开发人员当前如何执行此操作?

Jenkins CI Server的特定解决方案 - Webhook- webhook to jenkins for Bitbucket 已商业化在最新版本的Bit-bucket和当前价格约为4800美元左右,这是一个免费的免费产品,因此,想要节省雄鹿的人可以使用Bit-Bucket的Webhooks功能来解决替代解决方案: -

创建Webhook的步骤: -

bitbucket side

1)转到您的bitbucket存储库,单击"存储库"设置,在Webhooks选项的WorkFlow下,并创建一个Webhook。

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

b)在"名称"选项卡中,给您选择的任何名称

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

要照顾的事情詹金斯一侧: -

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

每当您的git回购观察到任何更改时,自动构建都会在詹金斯触发。默认情况下,推动触发器将被激活,如果要激活其他操作,请在创建Webhook时选择这些事件。

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

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

欢呼,

您的jenkins URL是否可以从您的bitbucket服务器访问?如果是的,那么这样做应该很简单。您将webhook添加为http://<url-of-jenkins>/git/notifyCommit?url=<url-of-repository>中的存储库。当Jenkins收到这篇文章时,它会自动触发与您在Webhook中使用该URL一起使用此git reto的工作。
但是,您还需要确保您的Build Schedule设置为这些作业。否则,它不会触发。您也可以在Webhook URL中指定一个分支
在此处查看Push Notification from repository
https://wiki.jenkins.io/display/jenkins/git Plugin

对于2022年7月以后这里的任何人,这是我遵循的简单步骤。

创建一个实时Jenkins URL

首先,使用nGrok创建从实时URL到本地Jenkins URL的隧道,因为直接将locahost:8080用作Bitbucket上的Webhook URL,因为Bitbucket无法识别您的本地计算机。

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端口上启动隧道EG 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                                       

基本上,单击的Web界面URL为您提供Web界面,以检查从您的Ngrok Live URL隧道的所有请求到本地主机。

转发URL基本上是您本地主机的代理,因此,当您要配置Webhook,而不是使用LocAhost:8080,而是将其替换为ngrok url eg eg https://syue-162-34-12-01.eu.ngrok.io,所有请求都将隧道tunnells tunnells tunnell tunnell to to localhost:8080

在Bitbucket Cloud上连接URL

其次,使用url JENKINS_URL/bitbucket-hook/配置您的bitbucket存储库(不需要凭据,但请记住拖延斜线),例如https://syue-162-34-12-01.eu.ngrok.io/bitbucket-hook/

如果您使用的是 Bitbucket Server 而不是云,或者您想了解更多,那么Jenkins的Bitbucket插件文档非常简单且易于理解,请参见Bitbucket插件

然后,您可以在Web接口URL或终端上检查所有Webhook请求,并通过Local -Host端口或Ngrok Live URL在Jenkins上检查构建日志。

免责声明:我没有弄清楚仅在特定分支更改时才启用构建,但是您可以配置Jenkins来仅建立一个特定的分支或根据您的需求可能需要的任何创建的分支,请检查<<strong>源代码管理和构建触发器

最新更新