Configuration as Code for Atlassian Bamboo

Configuration as code is an important prerequisite for continuous delivery (CD) to keep everything in source control. It allows us to have reproducible and auditable configurations. It also makes our configurations testable and easier to reuse, hence not violating the DRY principle. This is especially important with the rise of micro services. It is nothing special anymore to have thousands of build plans in a company. Maintaining their settings and keeping configurations in sync is a nightmare and very hard to achieve when you have to configure everything manually by clicking through UI configuration screens.

This is why a lot of CD tools already provide support for configuration as code: TeamCity provides a Kotlin-based DSL since version 10, Jenkins has its job DSL plug-in , Travis and Bitbucket Pipelines are using YAML, etc. But our CD tool of choice Atlassian Bamboo so far didn't provide support for this important principle.

This is where our newest plug-in Plan DSL for Bamboo comes in. It is conceptually identical to its similar named Jenkins job DSL plug-in. With this Bamboo plug-in, you can treat your Bamboo plan configurations as code with a Groovy-based DSL. Here's an example of a Groovy DSL configuring a build plan with a single stage and one job with a Maven 3 build task:

The DSL is open source and available on Github. Beside the DSL, the plug-in also allows users to script their Bamboo instances with Groovy the way they would like them to have. Here's an example of creating a global repository called myGlobalRepo which can then be used in the DSL to associate a build plan with it:

We use our plug-in since a couple of months internally for all our build plans. Maintenance tasks like changing the JDK version used to run Maven, adding a new build task to all build plans or adding a new environment to all deployment projects are now super easy. Where we originally had about 100 plans to build our Atlassian plug-ins which were all quite similar, we now have Groovy scripts with only a few hundred code lines (the DSL allows you to reuse common parts). This makes the whole build process very transparent and reproducible. Every time we make changes to these Groovy scripts and push them to our Git repository, our Bamboo plug-in will pick them up and propagate all changes to our build plans, as can be seen in this screen shot:



If you are interested, you can find more information on our Wiki. There's also a getting started guide and an API documentation. We also provide special DSL support for IntelliJ so that you have code completion, documentation, code lookup etc. for the DSL scripts. Happy hacking!

Comments

comments powered by Disqus