Freigeben über


Rollback tasks in Visual Studio Team Services and TFS 2015

 

Looking for a way to have your rollback logic in VSTS or TFS 2015 Release Definitions? Well you are in luck.

The https://marketplace.visualstudio.com/items?itemName=ms-devlabs.utilitytasks extension provides a nice set of features and the best one I like – Rollback

The issue so far has been that Release Management does not have pre-defined variables that indicate the status of the tasks executed in the job. That makes using an intelligent rollback script difficult. Rollback task facilitates exactly that. You can author a PowerShell script for reverting/ fixing the changes done to your environment by the deployment.

After installing this extension, you would see “PowerShell for rollback” task in the catalog.

You can use this for enabling rollback on failure of a deployment as follows:

1. Configure the environment deployment as you normally would.

2. Author a PowerShell script for rollback. To know which task failed in deployment, you can use an environment variable “Release_Tasks” that would be available for the script.

A sample of how to use this environment variable in the script is as follows. You can extend this to build the complete rollback script.

try

{

$jsonobject = ConvertFrom-Json $env:Release_Tasks

}

catch

{

Write-Verbose -Verbose "Error converting from json"

Write-Verbose -Verbose $Error

}

foreach ($task in $jsonobject | Get-Member -MemberType NoteProperty) {   

$taskproperty = $jsonobject.$($task.Name) | ConvertFrom-Json

Write-Verbose -Verbose "Task $($taskproperty.Name) with rank $($task.Name) has status $($taskproperty.Status)"

}

3. Add a PowerShell for rollback task to the environment for executing the rollback script.

4. Ensure that you enable “Run Always” control option for the rollback task, so that it shall be executed after any of the tasks fail. By default, no tasks shall be run after the first task fails unless marked “Continue on failure”.

The utility does come with other handy tasks like Tokenizer for managing your configuration, Zip & Unzip for well Zipping and Unzipping Smile Its interesting because with these you can now tokenize your Web.Config even if they are inside a web deploy package. But the Rollback is what gets the cherry as per me.

I have always loved the new Release Management platform and this makes me love it even more.

Comments

  • Anonymous
    July 22, 2016
    The comment has been removed
    • Anonymous
      August 29, 2016
      The tasks always only works on the agent just like any other task in the release definition. You can then use PS Remoting to perform any activity on the actual target servers.