简体   繁体   English

如何正确地将 Bitbucket 连接到 Jenkins

[英]How to connect Bitbucket to Jenkins properly

Since about 1 week now, Bitbucket doesn't (?) send a request to my Jenkins server.从现在大约 1 周以来,Bitbucket 没有 (?) 向我的 Jenkins 服务器发送请求。

I've set it all up like this:我是这样设置的:

Endpoint http://username:apitoken@jenkinshost/ Endpoint http://username:apitoken@jenkinshost/
username = username in Jenkins username = Jenkins 中的username
apitoken = apitoken connected to the username in Jenkins apitoken = apitoken 连接到 Jenkins 中的用户名
jenkinshost = my host where I run Jenkins jenkinshost = 我运行 Jenkins 的主机

Project name is a project Project name是一个项目
Token : The token I can setup in the per-project configuration. Token :我可以在每个项目的配置中设置的令牌。

I've done this according to this website: http://felixleong.com/blog/2012/02/hooking-bitbucket-up-with-jenkins .我根据这个网站做了这个: http://felixleong.com/blog/2012/02/hooking-bitbucket-up-with-jenkins : http://felixleong.com/blog/2012/02/hooking-bitbucket-up-with-jenkins
It did work, but it doesn't anymore.它确实有效,但现在不再有效。 Did Bitbucket change something? Bitbucket 改变了什么吗? How can I fix this?我怎样才能解决这个问题?

在此处输入图片说明

In order to build your repo after new commits, use Bitbucket Plugin .为了在新提交后构建您的存储库,请使用Bitbucket Plugin

There is just one thing to notice: When creating a POST Hook (notice that it is POST hook, not Jenkins hook), the URL works when it has a "/" in the end.只有一件事需要注意:当创建一个 POST 钩子时(注意它是 POST 钩子,而不是 Jenkins 钩子),当 URL 在末尾带有“/”时有效。 Like:像:

URL: JENKINS_URL/bitbucket-hook/
e.g. someAddress:8080/bitbucket-hook/

Do not forget to check "Build when a change is pushed to Bitbucket" in your job configuration.不要忘记在您的作业配置中选中“在将更改推送到 Bitbucket 时构建”。

I had a similar problems, till I got it working.我遇到了类似的问题,直到我开始工作。 Below is the full listing of the integration:以下是集成的完整列表:

  1. Generate public/private keys pair: ssh-keygen -t rsa生成公钥/私钥对: ssh-keygen -t rsa
  2. Copy the public key (~/.ssh/id_rsa.pub) and paste it in Bitbucket SSH keys, in user's account management console:复制公钥 (~/.ssh/id_rsa.pub) 并将其粘贴到用户帐户管理控制台中的 Bitbucket SSH 密钥中:在此处输入图片说明

  3. Copy the private key (~/.ssh/id_rsa) to new user (or even existing one) with private key credentials, in this case, username will not make a difference, so username can be anything:使用私钥凭据将私钥 (~/.ssh/id_rsa) 复制到新用户(或什至现有用户),在这种情况下,用户名没有区别,因此用户名可以是任何内容:在此处输入图片说明

  4. run this command to test if you can get access to Bitbucket account: ssh -T git@bitbucket.org运行此命令以测试您是否可以访问 Bitbucket 帐户: ssh -T git@bitbucket.org

  5. OPTIONAL: Now, you can use your git to to copy repo to your desk without passwjord git clone git@bitbucket.org:username/repo_name.git可选:现在,您可以使用您的 git 将 repo 复制到您的办公桌上,而无需 passwjord git clone git@bitbucket.org:username/repo_name.git
  6. Now you can enable Bitbucket hooks for Jenkins push notifications and automatic builds, you will do that in 2 steps:现在您可以为 Jenkins 推送通知和自动构建启用 Bitbucket 挂钩,您将分两步完成:

    1. Add an authentication token inside the job/project you configure, it can be anything:在您配置的作业/项目中添加一个身份验证令牌,它可以是任何东西:在此处输入图片说明

    2. In Bitbucket hooks: choose jenkins hooks, and fill the fields as below:在 Bitbucket hooks 中:选择 jenkins hooks,并填写如下字段:在此处输入图片说明

Where:在哪里:

**End point**: username:usertoken@jenkins_domain_or_ip
**Project name**: is the name of job you created on Jenkins
**Token**: Is the authorization token you added in the above steps in your Jenkins' job/project 

Recommendation: I usually add the usertoken as the authorization Token (in both Jenkins Auth Token job configuration and Bitbucket hooks), making them one variable to ease things on myself.

I was just able to successfully trigger builds on commit using the Hooks option in Bitbucket to a Jenkins instance with the following steps (similar as link):我只能通过以下步骤(类似于链接)使用 Bitbucket 中的 Hooks 选项成功触发构建提交到 Jenkins 实例:

  1. Generate a custom UUID or string sequence, save for later生成自定义 UUID 或字符串序列,保存以备后用
  2. Jenkins -> Configure Project -> Build Triggers -> "Trigger builds remotely (eg, from scripts)" Jenkins -> 配置项目 -> 构建触发器 -> “远程触发构建(例如,从脚本)”
  3. (Paste UUID/string Here) for "Authentication Token" (在此处粘贴 UUID/字符串)用于“身份验证令牌”
  4. Save节省
  5. Edit Bitbucket repository settings编辑 Bitbucket 存储库设置
  6. Hooks -> Edit: Endpoint: http://jenkins.something.co:9009/ Module Name: Project Name: Project Name Token: (Paste UUID/string Here) Hooks -> Edit: Endpoint: http://jenkins.something.co:9009/ Module Name: Project Name: Project Name Token: (Paste UUID/string Here)

The endpoint did not require inserting the basic HTTP auth in the URL despite using authentication, I did not use the Module Name field and the Project Name was entered case sensitive including a space in my test case.尽管使用了身份验证,端点不需要在 URL 中插入基本的 HTTP 身份验证,我没有使用模块名称字段,并且项目名称输入区分大小写,包括我的测试用例中的空格。 The build did not always trigger immediately but relatively fast.构建并不总是立即触发,而是相对较快。 One other thing you may consider is disabling the "Prevent Cross Site Request Forgery exploits" option in "Configure Global Security" for testing as I've experienced all sorts of API difficulties from existing integrations when this option was enabled.您可能需要考虑的另一件事是禁用“配置全局安全性”中的“防止跨站点请求伪造漏洞利用”选项进行测试,因为在启用此选项时,我经历了现有集成带来的各种 API 困难。

By iterating I learned that the Token field and the token in an endpoint can be the same.通过迭代,我了解到 Token 字段和端点中的令牌可以相同。 So I set them to be the same as the user token and it works!所以我将它们设置为与用户令牌相同并且它有效! Also check that the user has privileges to make a job.还要检查用户是否具有创建作业的权限。

Anyway, you can check access.log and see if Bitbucket makes a try or not.无论如何,您可以检查access.log并查看 Bitbucket 是否尝试。

詹金斯

PS Also a link to Bitbucket Documentation . PS 还有一个指向Bitbucket 文档的链接。 May some day it will become more useful.也许有一天它会变得更有用。

I am not familiar with this plugin, but we quite successfully use Bitbucket and Jenkins together, however we poll for changes instead of having them pushed from BitBucket (due to the fact our build server is hidden behind a company firewall).我不熟悉这个插件,但我们非常成功地将 Bitbucket 和 Jenkins 一起使用,但是我们轮询更改而不是让它们从 BitBucket 推送(因为我们的构建服务器隐藏在公司防火墙后面)。 This approach may work for you if you are still having problems with the current approach.如果您对当前方法仍有问题,则此方法可能对您有用。

This document on Setting up SSH for Git & Mercurial on Linux covers the details of what you need to do to be able to communicate between your build server and Bitbucket over SSH.这篇关于在 Linux 上为 Git 和 Mercurial 设置 SSH 的文档详细介绍了您需要做什么才能通过 SSH 在构建服务器和 Bitbucket 之间进行通信。 Once this is done, with the Git Plugin installed, go to your build configuration and select 'Git' under Source Code Management, and enter the ssh URL of your repository as the repository URL.完成此操作后,安装Git 插件后,转到构建配置并在源代码管理下选择“Git”,然后输入存储库的 ssh URL 作为存储库 URL。 Finally, in the Build Triggers section, select Poll SCM and set the poll frequency to whatever you require.最后,在 Build Triggers 部分,选择 Poll SCM 并将轮询频率设置为您需要的任何值。

I had this problem and it turned out the issue was that I had named my repository with CamelCase.我遇到了这个问题,结果证明问题是我用 CamelCase 命名了我的存储库。 Bitbucket automatically changes the URL of your repository to be all lower case and that gets sent to Jenkins in the webhook. Bitbucket 会自动将您的存储库的 URL 更改为全部小写,并在 webhook 中发送到 Jenkins。 Jenkins then searches for projects with a matching repository. Jenkins 然后搜索具有匹配存储库的项目。 If you, like me, have CamelCase in your repository URL in your project configuration you will be able to check out code, but the pattern matching on the webhook request will fail.如果您像我一样,在项目配置的存储库 URL 中使用 CamelCase,您将能够检出代码,但 webhook 请求上的模式匹配将失败。

Just change your repo URL to be all lower case instead of CamelCase and the pattern match should find your project.只需将您的 repo URL 更改为全部小写而不是 CamelCase,模式匹配应该会找到您的项目。

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

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