fritz stelluto
development for digital media
berlin, london

Tagging a Jenkins build automaticallyWeekly Challenge

The task: coming up with a branching strategy to work with Subversion and Jenkins.

About the challenge

In the previous weekly challenge I started setting up a continuos integration system for myself. The type of tasks I neded covered were listed as

  1. I check out the sources on a new machine and have a copy of the current production environment up and running
  2. I make changes to my theme / plugins on a workstation
  3. I upgrade WP itself or a plugin on a workstation
  4. I create new content on a workstation
  5. I edit content on the production server
  6. I update my local version with the latest comments
  7. I roll back changes if things go wrong
  8. I work on a workstation and want to carry on working on another, without the temporary code being deployed
  9. any of these can happen at the same time - e.g. I could start changing some code in my workstation, then make a quick amend to the content directly on the live site while out and about, then carry on working on the code change expecting the content amend not to be overwritten, and so on

This week I will look into the last two requirements, which boil down to 'establishing a branching strategy'.

Establishing a branching strategy

Feature: Establishing a branching strategy In order to avoid stale versions being published As a developer I need a branching or tagging strategy that ensures not all code commited to SVN is automatically deployed

Even with a single developer branching strategy can be tricky. Although the majority of my time is spent working on feature after feature, sequentially, that's not always the case. The typical case is that I have stable version (let's call it A), then start working on some changes at my normal workstation, therefore creating a new version (let's call it B), then when away from my normal environment I discover a mistake in the content that cannot wait. At that stage somehow I have to go back to version A and do the fix, thereby creating a new version, A'. I deploy A', and then I have to merge A' and B into yet a new version, C. I will then carry on working on my change on version C. Which I eventually deploy. Then I discover something wrong with it, and decide to roll back to A'.

The issue is to decide where in Subersion A, B, A', and C will live, which ones get automatically deployed, and how everything is marked so that it can easily be found. There are many debates over branching strategy, but they seem pretty much to boil down to one of two approaches.

I can either keep the trunk for work in progress, and whenever I need to deploy I'd create a new tag. In the example above, A would be a tag, B would be the trunk. When I realise I need A', I'd push the trunk (B) to a branch, revert the trunk to the tag (A), and do the fix on it. When the fix is ready I create a new tag A' and deploy it. Then I can merge the branch (B) with the new tag (A'), and merge back to trunk.

The benefits are

The drawbacks are

The alternative is to keep the trunk pristine and deploy from it, do any non trivial changes on a branch, merge back with trunk to deploy, and tag after deployment. So A would be the trunk, but it also exists as a tag. To start work on a new feature I create a branch B; when I realize I need to amend the live version and create A', I can either do that in a new branch or work directly on trunk if it's a small change. Either way, after the amend will have to be merged into trunk to be deployed; and deploying will create a tag for A'. Meanwhile work on B carries on as usual, I will just have to merge A' into it before pushing back to trunk.

The benefits are

The drawbacks are

The 'pristine trunk' approach sounds better to me. Conveniently, it also requires the least work, the only change I need to make to what I have set up so far would be to automatically tag the trunk after deployent.

Taggin a build automatically with Jenkins

Feature: Taggin a build automatically with Jenkins In order to be able to keep track of what was deployed, and roll back if needed As a developer I need to automatically tag each build

There task is made simple by the Subversion Tagging Plugin. It is simply a matter of installing, then going into the configuration page for the job. Under Post-build Actions there is now a Perform Subversion tagging on successful build. I enabled it, and set the Tag Base URL parameter as MY_SVN_ROOT/tags/${env['BUILD_NUMBER']}. The Tag Comment default is fine, and the Tag Delete Comment won't be needed as each tag will have a unique name. Tested, and it worked fine.

Challenge 100% complete

That's all there is to it. The only thing to be careful is to have the discipline to always create a new branch before any non-trivial bit of work, but that shouldn't be a problem. . In part 4 I shall deal with rolling back and deployment strategies.

Possible future expansions

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strong>