简体   繁体   English

如何通过 bitbucket-hook 将面包屑信息传递给詹金斯?

[英]How to pass crumb info via bitbucket-hook to jenkins?

curl -X POST http://xxx.yyy.zzz:5555/job/job-name/build --user john-devops-jenkins:11df3ed41129c5c7da1518e9c3149896de -H 'Jenkins-Crumb:31827a74a160347a641c87ddbc8e3b6e'

The above curl code with a post request is absolutely working fine in triggering the Jenkins build.上面带有 post 请求的 curl 代码在触发 Jenkins 构建时绝对可以正常工作。

Tried:试过:

Error: No valid crumb was included in the request错误: No valid crumb was included in the request

No luck still, How to configure bitbucket hook to container header information of crumb or how to pass it via url without relying on third party plugins?仍然没有运气,如何将 bitbucket 挂钩配置为 crumb 的容器标头信息,或者如何在不依赖第三方插件的情况下通过 url 传递它?

After a day of effort and brainstorming of how curl requests execute, finally resolved this issue by configuring bitbucket webhook as below:经过一天的努力和关于 curl 请求如何执行的头脑风暴,最终通过配置 bitbucket webhook 解决了这个问题,如下所示:

http://jenkins-username:jenkins-password@jenkins-url:5555/job/job-name/build?crumb=crumb_token. http://jenkins-username:jenkins-password@jenkins-url:5555/job/job-name/build?crumb=crumb_token。

Hope it helps, many questions are unanswered and all are suggesting to use third party or generic-web-hooks and so on.希望它有所帮助,许多问题都没有得到解答,并且都建议使用第三方或通用网络挂钩等。

The CRUMB_TOKEN is nothing but AUTHENTICATION_TOKEN which we generate through Jenkins configuration CRUMB_TOKEN 只不过是我们通过 Jenkins 配置生成的AUTHENTICATION_TOKEN

Follow these steps below to get authentication token:请按照以下步骤获取身份验证令牌:

  • Log in to Jenkins.登录詹金斯。
  • Click your name.点击你的名字。
  • Click Configure.单击配置。
  • Click Show API Token.单击显示 API 令牌。

Do not get confuse with this URL: JENKINS_URL/job/policy-vault/build?token=TOKEN_NAME which is mentioned next to Trigger builds remotely input option不要与此 URL 混淆: JENKINS_URL/job/policy-vault/build?token=TOKEN_NAME ,在触发器构建远程输入选项旁边提到

The correct URL which should be configured to build remotely is as below:应配置为远程构建的正确 URL 如下:

http://jenkins-username:jenkins-password@xxx.xxx.xxxx.xxx:5555/job/project-id/build?crumb=AUTHENTICATION_TOKEN http://jenkins-username:jenkins-password@xxx.xxx.xxxx.xxx:5555/job/project-id/build?crumb=AUTHENTICATION_TOKEN

The Webhooks should also be configured from Bitbucket Webhook 也应该从 Bitbucket 配置

Settings -> Repository Settings -> Webhooks

Title: PROJECT-XYZ-HOOK标题: PROJECT-XYZ-HOOK

URL: http://jenkins-username:jenkins-password@xxx.xxx.xxxx.xxx:5555/job/project-id/build?crumb=AUTHENTICATION_TOKEN网址: http://jenkins-username:jenkins-password@xxx.xxx.xxxx.xxx:5555/job/project-id/build?crumb=AUTHENTICATION_TOKEN

I am late here, but coming with the second edition of my answer for the folks who were blocked due to Jenkins's latest updates.我在这里迟到了,但我的第二版答案是针对因 Jenkins 的最新更新而被阻止的人们。

Now, with the latest Jenkins latest changes the Bitbucket webhook url looks as below:现在,随着最新的 Jenkins 最新更改,Bitbucket webhook url 如下所示:

http://jenkins-username:token-generated-for-loggedin-user@url:port/job/job-name/build?crumb=Jenkins-Crumb:crumb_long_token http://jenkins-username:token-generated-for-loggedin-user@url:port/job/job-name/build?crumb=Jenkins-Crumb:crumb_long_token

Crumb long token can be generated using the below command:可以使用以下命令生成 Crumb 长令牌:

wget -q --auth-no-challenge --user jenkins-username --password jenkins-password --output-document - 'http://jenkins-url:8081/crumbIssuer/api/xml?xpath=concat(//crumbRequestField,":",//crumb)' wget -q --auth-no-challenge --user jenkins-username --password jenkins-password --output-document - 'http://jenkins-url:8081/crumbIssuer/api/xml?xpath=concat(/ /crumbRequestField,":",//crumb)'

The output will be: Jenkins-Crumb:6f2dcf2182efd19511b2ebf7b787e%输出将是: Jenkins-Crumb:6f2dcf2182efd19511b2ebf7b787e%

To fetch token-generated-for-loggedin-usertoken-generated-for-loggedin-user

You must create it going to:你必须创建它去:

http://jenkins-url:8081/user/jenkins-username/configure http://jenkins-url:8081/user/jenkins-username/configure

In API Token, Click Generate.在 API 令牌中,单击生成。 Once the token is Generated, save it somewhere.生成令牌后,将其保存在某处。 The same should be passed to the URL that we form later.同样应该传递给我们稍后形成的 URL。

You can verify coming back to this URL: http://jenkins-url:8081/user/jenkins-username/configure, you will notice how many times that token was used for correct configuration.您可以验证返回此 URL:http://jenkins-url:8081/user/jenkins-username/configure,您会注意到该令牌用于正确配置的次数。

There are a few more changes that you should do along with this.除此之外,您还应该进行一些更改。

You must install: Bitbucket, bitbucket-pipeline, strict crumb issuer plugins from Manage Jenkins您必须安装:来自 Manage Jenkins 的 Bitbucket、bitbucket-pipeline、strict crumb issuer 插件

Finally, GoTo:最后,转到:

http://jenkins-url:8081/configureSecurity/ http://jenkins-url:8081/configureSecurity/

And in CSRF ProtectionCSRF 保护

Change Default Crumb Issuer to Strict Crumb IssuerDefault Crumb Issuer更改为Strict Crumb Issuer

Strict Crumb Issuer is what we installed above Strict Crumb Issuer是我们上面安装的

A lot of effort in the investigation made this change work.调查中的大量努力使这一改变奏效。 Hope this helps and unblocks.希望这会有所帮助并解除封锁。

I am using jenkins 2.350, and it worked for me, thanks Mithun.我正在使用 jenkins 2.350,它对我有用,谢谢 Mithun。 just need to update the following part as it took a while for me to work it out.只需要更新以下部分,因为我需要一段时间才能解决。

Crumb long token can be generated using the below command:可以使用以下命令生成 Crumb 长令牌:

Open the this link in browser;在浏览器中打开此链接; JENKINS_URL:PORT/crumbIssuer/api/xml you will get; JENKINS_URL:PORT/crumbIssuer/api/xml你会得到;

crumb:f5a4de9c398c97d178d2bb4~~~58ee3420a1d5e91ce2a773251a092832ae116c49442007e211bac4d2cd4b07ac968783445cd49411####6cd59d6af3df1d41bf

crumbRequestField: Jenkins-Crumb

Hence your long Crumb would be as:因此,您的长面包屑将是:

Jenkins-Crumb: f5a4de9c398c97d178d2bb4~~~58ee3420a1d5e91ce2a773251a092832ae116c49442007e211bac4d2cd4b07ac968783445cd49411####6cd59d6af3df1d41bf

Now add the above Crumb in the following URL at the end.现在在最后的以下 URL 中添加上面的 Crumb。

http://jenkins-username:token-generated-for-loggedin-user@url:port/job/job-name/build?crumb=Jenkins-Crumb:crumb_long_token

Rest just follow as Mithun said, Thanks休息按照米通说的,谢谢

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

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