简体   繁体   English

BitBucket 触发 Jenkins 工作

[英]BitBucket to trigger Jenkins job

I looked into BitBucket Plugin in Jenkins to have continuous integration setup.我查看了 Jenkins 中的 BitBucket 插件以进行持续集成设置。 However, I want to have a wrapper such that everytime a commit is made to BitBucket, how can I figure out the branch name where this commit was made.但是,我想要一个包装器,以便每次对 BitBucket 进行提交时,如何找出进行此提交的分支名称。 Instead of having separate jenkins job for each repo, I wanted to capture repo name and branch name in Jenkins which has a corresponding commit in Bitbucket and store this info in MySQL db.我不想为每个 repo 设置单独的 jenkins 作业,而是想在 Jenkins 中捕获 repo 名称和分支名称,它在 Bitbucket 中有相应的提交,并将此信息存储在 MySQL 数据库中。

Such that I can poll every day to see which all repos has changes and get a pulse.这样我就可以每天轮询以查看所有存储库都有变化并了解脉搏。

Any pointers on how to get the git branch and repo name in Jenkins job?关于如何在 Jenkins 工作中获取 git 分支和 repo 名称的任何指示?

Regarding the repository name, you can extract it from GIT_URL (assuming you have only one remote)关于存储库名称,您可以GIT_URL提取它(假设您只有一个远程)

You have other environment variables , including:您还有其他环境变量,包括:

  • GIT_BRANCH : the name of the current Git branch the Jenkins Git plugin is operating upon, and GIT_BRANCH :Jenkins Git 插件正在运行的当前 Git 分支的名称,以及
  • GIT_LOCAL_BRANCH : the name of the local Git branch when the “checkout to specific local branch” Jenkins Git plugin option is selected GIT_LOCAL_BRANCH :选择“checkout to specific local branch”Jenkins Git插件选项时本地Git分支的名称

But none of that tells you the name of the branch where the commit was made: git branch --contains <aSHA1> can return multiple branches (all the branches where that SHA1 is accessible, ie the branches whose tip commits are descendants of the named commit)但是这些都没有告诉您进行提交的分支的名称: git branch --contains <aSHA1>可以返回多个分支(可以访问该 SHA1 的所有分支,即提示提交是命名分支的后代的分支)犯罪)
The branch where the commit was created could habe been deleted or renamed since the creation.自创建以来,创建提交的分支可能已被删除或重命名。

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

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