Wherever I Lay My Hat: Release Management in TeamCity with Redgate DLM

Where you have multiple services, applications and databases in your environment, and perhaps with high levels of scrutiny and governance, you'll probably want a Release Management system for deploying database and application code together: You can, alternatively, use a separate Release Management component. But for simpler applications, you can use your existing build system such as TeamCity to deploy changes. Using a database deployment example, Richard Macaskill shows how.

Redgate DLM Automation, which features in this article, is now part of SQL Change Automation. Find out more

Do we need Release Management systems? Or rather, do we always need them? Do we always benefit by separating Release Management concerns from build and test?

Why not deploy changes directly from a build system such as TeamCity?

After all, build systems have many of the same capabilities, such as connection to an artifact repository, the ability to connect agents to multiple target servers to push updates for databases, web services etc. They can look after versioning and environment variables perfectly well.

2330-c2508b0a-d674-4784-a38b-c71e2247058

A database deployment pipeline using a dedicated Release Management system

Perhaps it’s worth stepping back for a moment to consider what we want to achieve.

There are obvious reasons most organizations carefully control how software is applied to the Production environment (perhaps all higher environments).

Are the business users ready? Do the customers need to be told? Are monitoring, backup, and disaster recovery configured correctly? Most of all, does it work as intended? (Or at all?)

Some of these things can be automated but there’s still co-ordination required, so normally someone needs to give the ‘ok’, hit the button, send the email.

In some industries, segregation of duties is also important; just as the cashier can’t validate their own cash float at the end of the day, the developer can’t directly change Production code (‘tweaking’ and other out-of-process changes being a major source of operational risk, and potentially fraud).

But even if promotion to Production is different, is it different enough to require another system?

Well, I’d say it depends.

Release Management as a term implies greater control than merely putting your software somewhere it can be used. Systems that specialize in providing such control often do excel in the visibility of deployed versions per environment. Separating the concerns can also make it easier to revert changes, aid time-to-resolution when faults occur, and assist in providing a clear audit trail.

I remember maintaining a spreadsheet of software versions per environment. With a dozen or more services, databases, and applications across five environments, it quickly became a fool’s errand. So seeing Octopus Deploy’s main interface, with its clear visualization of each environment, was an “Oh, wow” moment.

But you also can do all these things with mature and highly-customizable systems like TeamCity, or a combined build/test/release tool like Atlassian’s Bamboo. Moreover, software teams have – by definition – been solving these problems since software delivery began, using hand-built or generic systems for much of the time.

In this post, I’m going to look at using TeamCity for release management, rather than a specialist system like Octopus Deploy.

I’m going to use as my test case a database deployment using the Redgate Database Lifecycle Management (DLM) tools.

What am I trying to achieve?

I first thought about what concerns I wanted my release management process to address. They broke down as:

  1. Ensure everything deployed has been built and tested (separately, ahead of time).
  2. Force a manual intervention to make sure higher environments have appropriate protection. We want faults to surface early in the pipeline, and for team members to control (and take responsibility for) software promotion.
  3. Provide easy-to-understand information at the point of approval, so it’s not just box-ticking.

I’m imagining a situation where control is important, but recognizing simplicity is also valuable.

What features does TeamCity have to help me?

There were a few ways to address my concerns, but the following were sufficient for my scenario:

  1. Tagging of builds
  2. Artifact dependencies
  3. Environment variables
  4. Build report tabs

Step One – Separating Build from Release

Some unified systems have Release components; separate subsystems for addressing the Release concerns (Bamboo, coming soon in Visual Studio Team Services). With TeamCity, a simple project split is the way I’ve seen it done. Then it’s clear the CI project can be run at a different cadence (on each commit perhaps) to any of the deployment projects.

2330-a71ff4c8-b712-4fe0-bf63-59d8f0c7e4c

My deployments in this case are pretty simple; I’m using the PowerShell capabilities from Redgate’s  DLM Automation to deploy the database contained in the NuGet package created by the CI steps to a given environment. I’ve created the environment variables env.DatabaseServer and env.DatabaseName to deploy to different targets, but otherwise the deployments are the same.

I won’t go into detail, but the commands look like this;

Before anything can be deployed, I want to ensure the changes have been built and tested, and I want a releasable artifact, in this case a NuGet package, which contains what I need to deploy.

Only when the package has been created do I want to make it available to my Deployment project. So I’ll create an ‘artifact dependency’ in my Deployment project, which requires the package, and that I have tagged the build that created it with ‘Promote’.

Step Two – Tagging for Promotion

In my workflow, I’m happy for the dev team to control deployments to all the environments  except Production.

2330-e6ddd74d-03d1-4a31-81d2-0d3d76e4777

By configuring my Deployment steps to have an ‘artifact dependency’ on my Database Build project, I can ensure deployments will only pick up their artifacts from successful builds which I’m happy to promote. That setting is available in Build Configuration – Dependencies.

2330-4f6801b1-bd51-4421-89a6-33be225d013

Step Three – Tagging for Release

For a Release (which I’m defining as a deployment to Production in this case), I have an additional requirement.

I want to enforce a review of the changes as they’ve been applied to the UAT environment, and I want the reviewer to record their approval.  They’ll be reviewing the changes, build logs and any other artifacts I can make available to help them understand the change.

I’m using  DLM Automation to deliver a database, within which SQL Release creates a difference report (exported using the Export- DlmDatabaseRelease cmdlet in the script above) which I can surface within TeamCity on a Build Report Tab.  I’ve customized the build tabs to make the database changes easy to understand.

2330-9976d101-1904-4e26-a254-279acc5f747

The change report then becomes visible as with any other artifact, without requiring the reviewer to switch context. So the goal – of understanding what exactly has changed – is essentially achieved by working across the tabs in the Build Report.

2330-678c927c-d86a-47db-b3df-0e771d160b6

After the tabs have all been reviewed, I want the approver to tag this UAT build for Release.

2330-63f49aee-aefc-4b83-9400-4b36bd29a74

And for the Production Release step, I’ve added the requirement as a dependency.

2330-af2ec3ab-84e3-4281-bede-6a3a5eca99f

And that’s enough. Now I can run my Production Release, knowing:

  1. My deployment package has been built and tested
  2. The package was approved for Promotion
  3. It was deployed to the higher environments, up to UAT, successfully
  4. The same version, following a UAT sign-off which reviewed the specific changeset, was applied to Production
  5. An audit trail exists for all the above

Not perfect perhaps, but I’ve got a reasonable proof of concept for my project, and a workflow that has the right amount of governance for my requirements.

If I had segregation of duties concerns, I could add permissions to the process easily enough by enabling permissions-pre-project (off by default) and setting up groups.

If I just wanted to protect against Fat Finger Syndrome, I could add a review screen for the final deployment (Build Configuration Settings-Parameters-Configuration Parameters);

2330-f2938342-2697-45f5-ae48-e2bf26a62bb

Summary

For my requirements, I think TeamCity has given me a perfectly workable solution. The features for surfacing artifacts, tagging, and creating dependencies gave me a level of protection and oversight appropriate to my scenario.

The visibility of what version is in each environment is not as good as with Octopus Deploy, which might become an issue if the number of components grew. I’d also have to do some more work to be able to revert to specific versions easily.

My audit trail in this setup depends on interpreting some fairly detailed logs, so it might also be trickier to communicate quickly.

In an architecture with multiple dependent sub-systems, and especially if I had high levels of scrutiny and governance, I think I’d still consider a separate Release Management system, or a system with a segregated Release Management component. But it’s not necessarily a done deal.

How do you do your release management? What does governance mean in your team? I’d be fascinated to know.