简体   繁体   中英

BitBucket to trigger Jenkins job

I looked into BitBucket Plugin in Jenkins to have continuous integration setup. 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. 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.

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?

Regarding the repository name, you can extract it from GIT_URL (assuming you have only one remote)

You have other environment variables , including:

  • GIT_BRANCH : the name of the current Git branch the Jenkins Git plugin is operating upon, and
  • GIT_LOCAL_BRANCH : the name of the local Git branch when the “checkout to specific local branch” Jenkins Git plugin option is selected

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)
The branch where the commit was created could habe been deleted or renamed since the creation.

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