How to auto-Merge Bitbucket branches from Bamboo? - bitbucket

We are working on a POC with Bamboo and Bitbucket to do an auto-merge between the Master and Feature branches.
The task list is as follows:
Commit code in trunk
Get a repository polled bamboo build for the Trunk
Code gets Auto-merge in feature branch
Get a repository polled bamboo build for the Feature
I am able to do the first two steps but the next two are coming through.
What can be the configuration issue in this plan?
Thanks

You can establish automerging from your Bamboo plan.
Go to Plan Configuration -> Merging -> Branch merging enabled and you have 2 options:
Branch updater
Gatekeeper
For your user case you can use Branch updater, selecting the merged from the branch that you want and pushing on the branch that you want.

Related

jenkins pipeline configuration for starting builds on different branches with gerrit triger

I have recently started to experiment code review using Gerrit Code Review. Now I am trying to create a pipeline in jenkins and I have some issues with building based on a specific branch.
This is what I want to obtain:
I have 2 remote branches: master and develop.
For each new feature I create a local branch and I use git push origin HEAD:refs/for/develop to send the changes to review in order to be eventually merged into the remote's develop branch.
After the changes are accepted and the merge is finalized the code from the develop branch should be built and the result will be deployed to server_1.
At some point the develop branch will be merged into the master branch. The code from the master branch will be built and the result will be deployed to server_2.
I have managed to use Patchset Created event to start the build for the changes that are being reviewed. And probably I will use Change Merged event to start the build based on the develop branch after the changes have been merged
I made the following settings:
Refspec: $GERRIT_REFSPEC:$GERRIT_REFSPEC
Branches to build: $GERRIT_REFSPEC
disabled Lightweight checkout
I tried to use the Ref Updated event to start the build when I push a commit directly into the develop from the local develop branch but it results in a failure. Why is this happening? What settings should I make to make it work?
Also how do I deploy code to the right server based on the current branch name?

Bamboo build tying to undesired BitBucket Commit

Context
I have a BitBucket repo and a Bamboo Plan. The Bamboo Plan is tied to the Bitbucket repo in the "Repository" settings.
The Bamboo Plan "Branch" settings are set to create a new Branch when a new branch is created in the repo.
Issue
When I create a branch, bamboo makes a new branch and starts the build. The first build is tied to the latest commit which came from the original branch. I don't want to associate the new branch build with a commit to the original branch. (It causes more than one build to be associated with the commit.)
Desired Outcome
The build should only tie to new commits in the branch.
Solutions
Pull Request Trigger
I modified my bamboo plan to only trigger new bamboo branches when a Pull Request is created for the repo branch. It did give me the desired outcome. The downside is that commits to the branch will not be executed against the CICD process until a PR is created.
Is there a way to create Bamboo branches only on the first commit to a new repo branch?
No.
I'm sorry there isn't much you can do about this.

When Multibranch pipeline when job is trigged, what is stored in Jenkins workspace?

I am not sure if I am asking the question in right way.
When I am triggering the multi branch pipeline job and I do "checkout scm" in Jenkinsfile, does it checkout the pull request or Master + pull request?
It depends of your settings.
As I remember, multibranch pipeline builds pull requests in separated view and it can build as PR source branch and result of PR. It cloned your repo, checkouts target branch, merges source branch into it and runs your stages.
If you look at the logs you will see that it checks out the hash of the commit
example: git checkout 1fb651dfdcbea276627de0247bbf5047840cae4c
As for workspace, if you log in to the Jenkins machine where this is running you will see that each branch has a separated workspace. Here you will find the source code of the checked out branch. The separated workspace ensures that there is no conflict when working with multiple concurrent branch builds.

how do I create Master + PR branch and run some tests on it?

I am new to jenkins.
I want to build pipeline/jenkins job where once developer has pull request approved by other developers with 1 LGTM, I would build a new Master + the PR as new Master and run smoke tests.
If it passes, I will merge to the Master.
Thanks in advance!
You would need to setup a multibranch pipeline on a dedicate repo.
That dedicated repo would be one where (master+PR) branches are pushed to: their new branch would trigger the multibranch pipeline.
In order to push such branches (master+PR), you need another job which will:
periodically fetch from the origina repo
check for any PR branch with a +1 LGTM
create a new branch from master and merge that PR branch
push the resulting new branch to the dedicated remote repo mentioned before.

Prevent build of branch if another branch is not stable in jenkins multibranch pipeline

We use the gitflow branch strategy to maintain our repositories. This is linked to a multibranch pipeline in jenkins. That all works just fine.
Im wondering if it's possible to prevent building the master branch if another branch, let's say develop, has failed.
Usually we merge all code into develop, then into master for deploy. So if develop is failing, we'd prefer not to build and deploy master.
Instead of preventing a build on master, you shouldn't be merging. Only merge to master if your build on develop was successful and passed all tests.
Even when it comes the the merge - you can merge in a new 'merge branch' (taken from master) and deal with any conflicts/issues, test the build on that, and only if that succeeds does the actual merge to master take place.
Hope this helps.

Resources