0

I am currently using Teamcity to deploy a web application to Azure Cloud Services. We typically deploy using powershell scripts to the Staging Slot and thereafter do a manual swap (Staging to Production) on the Azure Portal.

After the swap, we typically leave the Staging slot active with the old production deployment for a few days (in the event we need to revert/backout of the deployment) and thereafter delete it - this is a manual process.

I am looking to automate this process using Teamcity. My intended solution is to have a Teamcity build kick off x days after the deployment build has suceeded (The details of the build steps are irrelevant since I'd probably use powershell again to delete the staging slot)

This plan has pointed me to look into Teamcity build chains, snapshot dependencies etc.

What I have done so far is

  • correctly created the build chain by creating a snapshot dependency on the deployment build configuration and
  • created a Finish Build Trigger BuildChain

At the moment, the current approach kickoffs the dependent build 'Delete Azure Staging Web' (B) immediately after the deployment build has succeeded. However, I would like this to be a delayed build after x days.

Looking at the above build chain, I would like the build B to run on 13-Aug-2016 at 7.31am (if x=3)

I have looked into the Schedule Trigger option as well, but am slightly lost as to how I can use it to achieve this. As far as I understand, using a cron expression will result in the build continuously running which is not what I want - I would like for the build B to only execute once.

Ahmad
  • 22,657
  • 9
  • 52
  • 84

1 Answers1

1

Yes this can be done by making use of the REST api.

I've made a small sample which should convey the fundamental steps. This is a PowerShell script that will clear the triggers on another build configuration (determined by the parameter value in the script) and add a scheduled trigger with a start time X days on from the current time (determined by the parameter value in the script)

1) Add a PowerShell step to the main build, at the end and run add-scheduled-trigger as source code

enter image description here

2) Update the parameter values in the script

  1. $BuildTypeId - This is the id of the configuration you want to add the trigger to

  2. $NumberOfDays - This is the number of days ahead that you want to schedule the trigger for

  3. There is admin / admin embedded in the script = Username / Password authentication for the REST api

One this is done you should see a scheduled trigger created / updated each time you build the first configuration

enter image description here

Hope this helps

Matt
  • 3,684
  • 1
  • 17
  • 19
  • Sounds promising, would this still work within the context of build chains? I've also been pointed to https://github.com/rhysgodfrey/team-city-delayed-finish-build-trigger from a collegue – Ahmad Aug 10 '16 at 12:58
  • ooo nice - I didn't know a plugin existed. If you have a build chain setup then TeamCIty is taking care of working out if it needs to rebuild the first configuration or not based on the settings you made for the dependency relationship. – Matt Aug 10 '16 at 13:07
  • I'll give this a try when i get a chance and let you know how it works out – Ahmad Aug 10 '16 at 13:08