Creating a rollback build for TeamCity

We have a nightly build of TeamCity, which releases the latest code on our test site, restores the database according to the production, and then applies any changes to the schema and data that we have in TFS. If this nightly assembly failed, the website does not work until we manually fix the code and / or database scripts and restart the assembly.

I would like to automatically roll back to the last successful build, so the website is accessible, despite any break in work.

After spending some time investigating, here is my suggested solution:

  • Nightly builds are done by creating a new tag in TFS (something like Nightly-build- {build number})
  • Create a new TeamCity build that starts after the buildโ€™s overnight build
  • Find the last successful nightly build number
  • Get version related to this build number tag in TFS
  • Rollback assembly (it does not matter, only the night assembly completed successfully)

What I don't know is how to create a rollback version based on a shortcut.

Any help for this or another solution would be appreciated.

Greetings.

+4
source share
1 answer

Reasonable use of the TeamCity REST API can work here. I am a little versed in this issue , which covers part of the same territory. You could do something like this (and I'm just spitballing here):

  • Create the VerifyBuild configuration according to your step 2.
  • Create a RollbackBuild configuration that can be deployed from a given label whose assembly number is parameterized as %rollback.buildnumber%

In VerifyBuild :

  • Use the Rest API for a list of recent nightly production deployments.
  • If the last deployment was SUCCESS, then everything is ready.
  • If the last deployment was FAILURE, then get the build number of the last successful build.
  • Use the Rest API for set %rollback.buildnumber% RollbackBuild to the last successful build number.
  • Use the Rest API for a RollbackBuild queue .

I suggest this method because I donโ€™t know how you would dynamically retrieve the correct shortcut for RollbackBuild before validation, so I use VerifyBuild to populate it.

+4
source

All Articles