0

I started to work with Jenkins for a week. I have referred the Jenkins plugins and implemented a Jenkins to build the source. Now, I need to get all the active branches in a BitBucket cloud repository from a Jenkins job(automatically) and build the sources for the particular branch alone if commits done on the same branch.

Note: If any new branch created from the Bitbucket cloud repository, then that should also be detected and start the Jenkins job if commit done for the branch source.

Could anyone please guide me on this to get all the active branches in a Bitbucket cloud repository using Jenkins? Is there any plugin available for this?

I have also referred the below links. But, this link specified to trigger the jenkins job for the particular branch and we need to manually include the branch name in jenkins job.

1) Is it possible to trigger Jenkins from one specific branch only?

2) How can I make Jenkins only build feature branches if they have changed when triggering from bitbucket

3) BitBucket+Jenkins: Trigger build only when specific branch is changed

4) How do I get Jenkins to build on push to a BitBucket git repository?

Thanks.

Community
  • 1
  • 1
  • Initiate a git repository at your bitbucket URL, it should work. Then, with your build triggers and bitbuckets webhooks, you can do all your 4 questions – Alexi Coard Jul 29 '16 at 11:08
  • Do we need to add the branches manually in Jenkins job if any new branches created? Also, above 4 are not my questions. Just i referred the 4 stackoverflow link. – VADIVEL NATARAJAN user2505309 Jul 29 '16 at 11:10

3 Answers3

0

Download the BitBucket plugin

1) On your job Source Code Management tab, initiate a GIT repo and set it to your bitbucket project URL, you can then change the branches to listen

2) You can use the bitbuckets webhooks (on bitbucket in the settings menu)

3) Same as above, you can manage your webhooks to trigger only when a given branch is pushed

4) Create a webhooks triggered on push event

To answer your comment, it depends, if your go on the configure menu of your job, Jenkins will retrieve you all the branches, else if you want to do it manually (for example shell), I guess you can use git branch or something like that and store them in a variable.

It seems that you can't trigger a build on branch created, but maybe by listening on a commit it should do the work.

Good luck for your Jenkins project

Alexi Coard
  • 7,106
  • 12
  • 38
  • 58
  • Is this work for bitbucket cloud? i could not see the hook option there. – VADIVEL NATARAJAN user2505309 Jul 29 '16 at 11:50
  • It works for sure on bitbucket, the classic one, however looking at Bitbucket cloud, they use Bamboo, which is a continuous integration software too, maybe you should look around this. There is also certainly a Jenkins plugin for bamboo. I don't know bucket cloud enough to help you there. But I realised the same thing as you (nearly) on bitbucket classic – Alexi Coard Jul 29 '16 at 11:53
0

I hope this helps:

https://wiki.jenkins.io/display/JENKINS/Pipeline+Multibranch+Plugin

This plugin automatically creates a new Jenkins job whenever a new branch is pushed to a source code repository.

Litty Philip
  • 1,027
  • 10
  • 12
0

Use the Bitbucket Branch Source plugin. This plugin automatically detects and creates jobs for all extant PRs & branches on all extant repositories in a Bitbucket Server or Bitbucket Cloud project.

jayhendren
  • 4,286
  • 2
  • 35
  • 59