Bamboo selective branch deployment
Asked Answered
T

3

5

I am using Bamboo and have two branches: branch1 and branch2 as well as master.

When I build master the resulting artefact is deployed to a nexus repository as expected. However, when I build any of the branches they too get deployed to nexus.

Ideally what I want to happen is that only master is deployed to nexus.

Since both master and the branches use the same stage/job how would you configure this?

Turning answered 6/1, 2015 at 16:43 Comment(0)
T
5

In the end we settled on a solution which involved using branch variables. Using these we could then insert a value as a maven target i.e. mvn clean ${bamboo.variableName}. By default the variable had the value install but the master branch in Bamboo would override the variable and set it to deploy. This way all branches will just build and test whereas master would build, test and deploy.

Turning answered 7/1, 2015 at 11:27 Comment(2)
How do you set different variable values for different branches? I don't see that functionality described in the documentationSaveall
On the branch plan itself you can override variables. Note that you cannot override the variable for the main branch, so you have to convert it to a plan branch if that's the one you would like to deploy.Belier
T
3

You should be able to select which branch is deployed when setting up an automatic deployment, documented here - https://confluence.atlassian.com/display/BAMBOO/Deployments+from+branches#Deploymentsfrombranches-Automatedbranchdeployment

Tatianatatianas answered 6/1, 2015 at 16:55 Comment(3)
Hmmm this requires the use of a deployment project if I am not mistaken. Since I am only interested in deploying to Nexus I don't think it would be right to setup a deployment project just to deploy here. I wonder if its possible without the use of a deployment project?Turning
It would yes, I've not used Nexus so I'm not sure what the workflow for it should be but it might be worth considering using a Deployment Project for that final stage. Bamboo attempts to separate build and deployment so if you ever need to 'deploy' elsewhere (or just to an new environment) it's more easily manageable - docs. Like I say, that might not immediately fit the Nexus workflow but I don't think you'll get the result you want from just a build project.Tatianatatianas
Oh okay, thanks for the suggestion. Nexus is an artefact repository. We build our projects using Maven, it then uploads the resulting JAR file to the Nexus server that stores the artefact so that other people can retrieve it and use it in their projects. With this in mind a deployment project seems quite heavyweight. Nevertheless its good to know that its a possibilityTurning
H
2

The solution that worked best for me was to use a script to decide what to do. So, instead of a maven task, I created script task and made it decide which command to run based on the branch being built:

echo "Starting build for branch:"
echo $bamboo_planRepository_branchName

if [ $bamboo_planRepository_branchName = "development" ] ; then
    echo "Executing mvn clean deploy -U"
    mvn clean deploy -U
else
    echo "Executing mvn clean install -U"
    mvn clean install -U
fi

$bamboo_planRepository_branchName is a variable provided by Bamboo.

Homoousian answered 4/3, 2016 at 19:33 Comment(1)
Note that you get quite a few duplicates of this script - in my case I'd have this script 9 times because deployment is a bit more complex.Dogcart

© 2022 - 2024 — McMap. All rights reserved.