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
...
Source | Bamboo | Advantages |
---|
Java | 6.0 and higher | - Provided by Atlassian
- Finer grained access for more complete and complex requirementsWell
- 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 skills teams and people those comfortable with command line scriptingusage
|
Export Existing Plans
Whatever option you choose, the new Bamboo CLI exportPlan action can help you with your journey and automation.
Info |
---|
title | EAP - exportPlan is marked experimental in 6.4 |
---|
|
- Atlassian considers export to java as beta for Bamboo 6.0 - export may be incomplete or not able to be imported without changes. The CLI exportPlan uses the Bamboo provided export for java.
- Export plan to CLI is new in Bamboo CLI 6.4 and has some limitations as well in terms of completeness that will be addressed mostly in release 6.5.
|
Code Block |
---|
language | bash |
---|
title | Export to Bamboo Specs Java |
---|
|
--action exportPlan --plan EXAMPLE-PLAN --type java --file example.java |
Expand |
---|
title | See generated java source |
---|
|
Code Block |
---|
| // 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));
}
} |
|
Code Block |
---|
language | bash |
---|
title | Export to a CLI Script |
---|
|
--action exportPlan --plan EXAMPLE-PLAN --file example.txt |
Expand |
---|
title | See generated CLI source |
---|
|
Code Block |
---|
language | bash |
---|
linenumbers | true |
---|
| # 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 CHECKOUT \
--name "Source Code Checkout" \
--description "Checkout Default Repository"
-a addTask --plan @plan@ --job @job@ \
--taskKey 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 CLI_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.
Code Block |
---|
language | bash |
---|
title | Export All Plans as Java Files |
---|
|
--action runFromPlanList --project @all --common "--action exportPlan --plan @plan@ --type java --file export/@project@/@plan@.java"
or
|
Code Block |
---|
language | bash |
---|
title | Export All Plans as CLI Scripts |
---|
|
--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. Use movePlan to another location (project or key change) in order to save all logs.
Code Block |
---|
language | bash |
---|
title | Create same plan key as export |
---|
|
--action run --file example.txt --continue |
Code Block |
---|
language | bash |
---|
title | Create new plan key |
---|
|
--action run --file example.txt --findReplace "--plan EXAMPLE-TEMPLATE:--plan EXAMPLE-PLAN1, --name TEMPLATE:--name Plan1" --continue |