简体   繁体   中英

bitbucket webhook to jenkins with branch name

i have a bitbucket repo that sends webhook to trigger jenkins job. 位桶网络钩子

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: 使用变量的方式,以及我需要的变量

so i've edited the url with an "&branch=$BITBUCKET_BRANCH" at the end, but it won't work. 触发的 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. which is a json that contains all of the details about the webhook: 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.

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

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: 在此处输入图片说明

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. 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 may simply be available in the job, depending on the version of Jenkins and type of job you are using. 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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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