Parallel deployment with Azure PowerShell VSTS Release Tasks

Running Azure PowerShell commands in parallel to speed up your deployments

Advertisements

Making better software starts with shortening the time it takes to get feedback. The less time between you start an action and its result, the bigger the chance you will do anything with the feedback. Faster is better!

Let’s see how we can apply this to our VSTS Build and Release CI/CD pipeline. How can we shorten the execution time? When using a custom build and release task or a PowerShell task you can benefit from parallel processing. For normal PowerShell tasks you can use a Start-Job construction or make a workflow to do parallel processing. However, when you are running your task in a Azure PowerShell this will not work because the parallel job or workflow thread will lose the Azure context.

After some research I figured out that Invoke-Parallel will work with Azure PowerShell for deploying ARM templates. It is required to make the Invoke-Parallel command available by importing or coping the module. You can then use it in an Azure PowerShell task or in your custom build or release task. The sample script below shows how to apply this technique.

cls
Login-AzureRMAccount #Login to Azure for the sample

@{'1','2','3'} | Invoke-Parallel -ImportModules -ScriptBlock {
    Write-Verbose 'Deploy $_';
    New-AzureRmResourceGroupDeployment ... #Deploy or other actions
}

The main purpose for this solution was a very long running deployment. By default the VSTS release cannot take takes longer than 30 minutes. If it runs longer it will abruptly end with the following error:

The job exceeded the maximum allowed time of 00:30:00 and was stopped. Please visit http://manage.windowsazure.com/#

There is a possibility to increase this deployment time, but this is a paid solution. In my opinion a 30 minutes deployment already feels a bit longish. If you happen to have Azure PowerShell tasks or custom Azure tasks, you can quickly optimize these by applying this parallel execution.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s