TodayI would like to show you how easy you can create conventions on your branching model and map these conventions to deployment / environment profiles.

Where we come from

Usually a project needs to have different settings for different environments (production, testing, staging, etc. pp.). Maven provides for this a nice plugin, but Gradle lacks of this kind of plugin. But, to be honest, introducing something that fills this gap is quite easy. For an example see source code below

As you see, it checks if the property ‘env’ is set, if so it uses this value otherwise developer as environment. After this setup it reads a config file in groovy style with the config slurper.

It works fine, so what’s the issue?

Even if the default is ok (test environment) it annoys me that have to type every time something like -Penv=production . It happens often, that I forgot to explicitly set the branch to production or staging (our CI-Server remembers this for me, but I need to build the bugfix branches for example on my local machine). Starting from this point I discussed with a colleague of mine the usage of some conventions on our branch layout (mostly inspired by http://nvie.com/posts/a-successful-git-branching-model/; we just added explicite bugfix branches on top of the release branch). We came up with the observation that we could map all branches to different environments

Branch to Environment / Profile mapping

The dashed lines are alternative deployment environments whereas the filled lines are the default deployment environments from our perspective. As you see, we make a really simple and understandable mapping convention. After producing this mapping I started to investigate how complex it will be to check what’s my current branch in GIT is. This can be done fairly easy with

At my employment we started implementing a profiler plugin for gradle, that will include this with a little bit more sugar and some additional conventions. We will share this plugin via oss-sonatype / github. Stay tuned!

My colleague created a nice extension for the zShell, I’ll ask him if we can share this here. If so I’ll put his script here during the next days.