简体   繁体   English

带有分支名称的 jenkins 的 bitbucket webhook

[英]bitbucket webhook to jenkins with branch name

i have a bitbucket repo that sends webhook to trigger jenkins job.我有一个发送 webhook 来触发 jenkins 工作的 bitbucket 存储库。 位桶网络钩子

http://:8080/buildByToken/buildWithParameters?job=webhook_me&token=ti want to send with the webhook the bitbucket branch name, so i search the web for the right way to use Environment variables on bit bucket and i've found this site: http://:8080/buildByToken/buildWithParameters?job=webhook_me&token=ti 想用 webhook 发送 bitbucket 分支名称,所以我在网上搜索了在位桶上使用环境变量的正确方法,我找到了这个站点: 使用变量的方式,以及我需要的变量

so i've edited the url with an "&branch=$BITBUCKET_BRANCH" at the end, but it won't work.所以我在最后编辑了带有“&branch=$BITBUCKET_BRANCH”的网址,但它不起作用。 触发的 Jenkins 作业以及尝试回显分支名称

any ideas what should i do in order to send the webhook with the branch name?有什么想法我应该怎么做才能发送带有分支名称的网络钩子?

*******EDIT******* *******编辑*******

i saw that there is something called Bitbucket event payload.我看到有一种叫做 Bitbucket 事件负载的东西。 which is a json that contains all of the details about the webhook: https://confluence.atlassian.com/bitbucket/event-payloads-740262817.html这是一个包含有关 webhook 的所有详细信息的 json: https ://confluence.atlassian.com/bitbucket/event-payloads-740262817.html

but i can't figure a way how to use it and pull it's data from jenkins.但我想不出如何使用它并从 jenkins 中提取数据的方法。

i think that, this is the way to solve this, but i don't know how to use it.我认为,这是解决这个问题的方法,但我不知道如何使用它。

i've found a way to do it, it works for me.我找到了一种方法,它对我有用。 you need to use the bitbucket plugin: Bitbucket Plugin你需要使用bitbucket插件: Bitbucket Plugin

then inside the job you need to specify the branch that will trigger the job after a push and check the marked checkbox:然后在作业中,您需要指定推送后将触发作业的分支并选中标记的复选框: 在此处输入图片说明

then on the bitbucket create a webhook with the following URL: http://:/bitbucket-hook/ Like so:然后在 bitbucket 上创建一个具有以下 URL 的 webhook: http://:/bitbucket-hook/像这样: 在此处输入图片说明

then push something to this repository and that branch, and there you go!然后将一些东西推送到这个存储库和那个分支,然后你就可以了! if you try to push to a different branch, the job won't be triiggered如果您尝试推送到不同的分支,则不会触发该作业

The $BITBUCKET_BRANCH is only available in the Jenkins job. $BITBUCKET_BRANCH 仅在 Jenkins 作业中可用。 You are just literally passing the text "$BITBUCKET_BRANCH as the "branch" parameter. You can't pass in an environment variable like that.您实际上只是将文本“$BITBUCKET_BRANCH”作为“branch”参数传递。您不能像这样传递环境变量。

$BITBUCKET_BRANCH may simply be available in the job, depending on the version of Jenkins and type of job you are using. $BITBUCKET_BRANCH 可能只是在作业中可用,具体取决于 Jenkins 的版本和您使用的作业类型。 In a pipeline job, this would be easy to access (if you have the right version of things).在流水线作业中,这很容易访问(如果您有正确的版本)。 You don't need to pass it in unless you are trying to give it some other branch.除非你想给它一些其他的分支,否则你不需要传递它。 In that case, you will need to see if you can get the branch on the bitbucket side to pass in to Jenkins.在这种情况下,您需要查看是否可以将 bitbucket 端的分支传递给 Jenkins。

您是否尝试过使用类似 jenkins 的变量 ${BITBUCKET_BRANCH} 而不是 $BITBUCKET_BRANCH ,后者更像 shell 变量?

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

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