Story
We have been on a DevOps journey with Plan Creation Scripting for almost 2 years to realize the goal of having Bamboo configuration as code. Internally, we have 100's of plan configurations under source control with the ability to deploy them to multiple Bamboo servers in an instance. It has proven to be an highly productive endeavor. We made the investment to create these script from scratch and, in the process, significantly improved the performance and reliability of our builds. We are probably on our 3rd generation of major improvements in our plan construction including standardization, common elements, support tools, and more maintainable scripts.
Now there has been a major advances with Bamboo CLI 6.4 with the addition of exportPlan and the ability to kick start configuration from source efforts in your company as you accelerate your DevOps journey.
Atlassian Endorses Configuration as Code for Bamboo
With Bamboo 6.0, has made the initial steps to support Configuration as code with the release of Java based configuration source. They have articulated the advantages of this approach - Advantages of Configuration as Code.
Options
Source | Bamboo | Advantages |
---|
Java | 6.0 and higher | - Provided by Atlassian
- Finer grained access for more complete and complex requirements
- Supports modular components to help enable standardization and reuse
- Better suited for teams with Java programming and IDE skills
|
CLI | 5.10 and higher | - Higher level abstraction - more readable
- Same syntax as dynamic plan modifications and related automation
- Supports modular components to help enable standardization and reuse
- Individual actions enable better problem determination
- Option to continue past individual errors on plan creation or modification
- Better suited to DevOps teams and those comfortable with command line usage
|
Export Existing Plans
Whatever option you choose, the new Bamboo CLI exportPlan action can help you with your journey and automation.
--action exportPlan --plan EXAMPLE-PLAN --type java --file example.java
See generated java source
// Exported from https://examplegear.com running Bamboo 6.0.0 on 2017-05-02 by automation using the Bamboo CLI 6.4.0-SNAPSHOT
import com.atlassian.bamboo.specs.api.builders.AtlassianModule;
import com.atlassian.bamboo.specs.api.builders.BambooKey;
import com.atlassian.bamboo.specs.api.builders.BambooOid;
import com.atlassian.bamboo.specs.api.builders.Variable;
import com.atlassian.bamboo.specs.api.builders.plan.Job;
import com.atlassian.bamboo.specs.api.builders.plan.Plan;
import com.atlassian.bamboo.specs.api.builders.plan.Stage;
import com.atlassian.bamboo.specs.api.builders.plan.artifact.Artifact;
import com.atlassian.bamboo.specs.api.builders.plan.branches.BranchCleanup;
import com.atlassian.bamboo.specs.api.builders.plan.branches.PlanBranchManagement;
import com.atlassian.bamboo.specs.api.builders.project.Project;
import com.atlassian.bamboo.specs.api.builders.task.AnyTask;
import com.atlassian.bamboo.specs.api.model.BambooKeyProperties;
import com.atlassian.bamboo.specs.api.model.BambooOidProperties;
import com.atlassian.bamboo.specs.api.model.VariableProperties;
import com.atlassian.bamboo.specs.api.model.plan.JobProperties;
import com.atlassian.bamboo.specs.api.model.plan.PlanProperties;
import com.atlassian.bamboo.specs.api.model.plan.StageProperties;
import com.atlassian.bamboo.specs.api.model.plan.artifact.ArtifactProperties;
import com.atlassian.bamboo.specs.api.model.plan.branches.PlanBranchManagementProperties;
import com.atlassian.bamboo.specs.api.model.project.ProjectProperties;
import com.atlassian.bamboo.specs.api.model.task.AnyTaskProperties;
import com.atlassian.bamboo.specs.builders.task.CheckoutItem;
import com.atlassian.bamboo.specs.builders.task.ScriptTask;
import com.atlassian.bamboo.specs.builders.task.VcsCheckoutTask;
import com.atlassian.bamboo.specs.model.task.ScriptTaskProperties;
import com.atlassian.bamboo.specs.model.task.VcsCheckoutTaskProperties;
import com.atlassian.bamboo.specs.util.BambooSpecSerializer;
import com.atlassian.bamboo.specs.util.MapBuilder;
public class HllSample {
public static void main(String... argv) {
Plan rootObject = new Plan(new Project()
.oid(new BambooOid("1kbtpp1cvu8by"))
.key(new BambooKey("ZEXPORT")),
"Base",
new BambooKey("BASE"))
.oid(new BambooOid("1kbk0hfzo0g5d"))
.stages(new Stage("FIRST")
.jobs(new Job("JOB1",
new BambooKey("JOB1"))
.artifacts(new Artifact()
.name("out.txt")
.copyPattern("out.txt"))
.tasks(new VcsCheckoutTask()
.description("Checkout Default Repository")
.checkoutItems(new CheckoutItem().defaultRepository()),
new ScriptTask()
.inlineBody("echo xxx > out.txt"),
new AnyTask(new AtlassianModule("org.swift.bamboo.acli:bamboo"))
.configuration(new MapBuilder()
.append("projectFile", "")
.append("scriptLocationTypes", "")
.append("scriptLocation", "INLINE")
.append("scriptBody", "--help")
.append("label", "")
.append("testChecked", "")
.append("directory", "")
.append("script", "")
.append("testDirectoryOption", "")
.append("environmentVariables", "")
.append("testResultsDirectory", "")
.append("buildJdk", "")
.append("workingSubDirectory", "")
.build()))))
.linkedRepositories("cli")
.variables(new Variable("v1",
"xxx"))
.planBranchManagement(new PlanBranchManagement()
.delete(new BranchCleanup())
.notificationForCommitters());
System.out.print(BambooSpecSerializer.dump(rootObject));
}
}
--action exportPlan --plan EXAMPLE-PLAN --file example.txt
See generated CLI source
# Exported from https://examplegear.com running Bamboo 6.0.0 on 2017-05-02 by automation using the Bamboo CLI 6.4.0-SNAPSHOT
-a createOrUpdatePlan --plan ZEXPORT-BASE --name "Base" --description ""
-a removeRepository --plan @plan@ --repository @all
-a addRepository --plan @plan@ --repository "cli"
-a removeBranch --plan @plan@ --branch @all
-a addBranch --plan @plan@ --branch 2.5.0 \
--name "ZEXPORT - Base - 2.5.0"
-a removeVariables --plan @plan@ --field1 @all
-a addVariables --plan @plan@ --field1 "v1" --value1 "xxx"
-a removeStage --plan @plan@ --stage @all
-a addStage --plan @plan@ --stage "FIRST"
-a addJob --plan @plan@ --stage @stage@ --job JOB1 \
--name "JOB1"
-a addArtifact --plan @plan@ --job @job@ \
--artifact "out.txt" \
--copyPattern "out.txt"
-a addTask --plan @plan@ --job @job@ \
--taskKey com.atlassian.bamboo.plugins.vcs:task.vcs.checkout \
--name "Source Code Checkout" \
--description "Checkout Default Repository"
-a addTask --plan @plan@ --job @job@ \
--taskKey com.atlassian.bamboo.plugins.scripttask:task.builder.script \
--name "Script" \
--field1 "scriptLocation" \
--value1 "INLINE" \
--field2 "scriptBody" \
--value2 "echo xxx > out.txt" \
--field3 "interpreter" \
--value3 "RUN_AS_EXECUTABLE"
-a addTask --plan @plan@ --job @job@ \
--taskKey org.swift.bamboo.acli:bamboo \
--name "Bamboo CLI" \
--field1 "scriptLocation" \
--value1 "INLINE" \
--field2 "scriptBody" \
--value2 "--help"
Export All Plans With One CLI Action
One action will export all your existing plans to a directory. Alternatively, be more selective by doing this by project and using regex based filtering on names.
--action runFromPlanList --project @all --common "--action exportPlan --plan @plan@ --type java --file export/@project@/@plan@.java"
--action runFromPlanList --project @all --common "--action exportPlan --plan @plan@ --file export/@project@/@plan@.txt"
Import - Creating or Updating Plans
For java, use your IDE of choice and refer to the Atlassian documentation.
For CLI, use one of the following approaches depending on your situation. We use the --continue option to keep going even if something fails along the way. The export was constructed to support updating an existing plan without deleting it first. This is important to maintain references from other plans. Also, some history is retained, but due to a Bamboo limitation, previous logs are lost.
--action run --file example.txt --continue
--action run --file example.txt --findReplace "--plan EXAMPLE-TEMPLATE:--plan EXAMPLE-PLAN1, --name TEMPLATE:--name Plan1" --continue