Script tasks in DevOps Pipelines - June 2020

So it's been a few months since the last instalment,

https://www.linkedin.com/pulse/visual-studio-code-marketplace-extensions-paul-trotman

Since the journey started from Infrastructure Ops to DevOps it is the Dev part which has been the most challenging, however when you finally get the hang of it the most rewarding.

So far the pattern for deploying solutions with Azure DevOps pipelines I've been using is

  • ARM Template
  • Script Task: Azure PowerShell
  • Script Task: Azure CLI
  • C# (The true strength of a DevOps team coming together, the C# work is not me)

The C# is the step towards application resilience and a massive benefit of working together

  1. On application startup check certain dependant Azure resources are present.
  2. If they are not recreate them. (We have found this works effectively for resources such as Queues in Blob Storage and Subscriptions in ServiceBus)

For now back to the PowerShell as C# is on the list to learn, just not yet. Also to note with the PowerShell script task you still need a Service Connection scoped to either the subscription and or resource group containing the objects to be created or managed, I always try resource group first then if that fails subscription (There are a few resources which require subscription access, however scoping to resource group reduces the risks in deployments substantially) extra reading makes all the further development easier https://docs.microsoft.com/en-us/powershell/azure/?view=azps-4.2.0

So back to the pipeline, where parameter settings either cannot be set in a template or it is more flexible to have it outside of one, Azure DevOps pipelines have two Microsoft script modules Azure PowerShell and Azure CLI both which have two options:

1.Script filePath

2. In-line

Option 2. In-Line, I found has a maximum character limit of 5000 so you are limited if you are creating longer scripts. Also I've found it better practice and easier on-going management for the scripts to be kept in source control instead of the pipeline.

First the modules are available in the Market Place

No alt text provided for this image

Select the Service Connection and In-line Script, then scroll down and also select latest version and Save

No alt text provided for this image

The script can then be tested in PowerShell ISE or VS Code (At writing I have not found the VS Code plugin for Azure-Connect when MFA enabled so PowerShell ISE is used for testing) then copy and paste into the in-line script window. Finally the task is saved then Create Release to run the script.

Option 1. Script Filepath Connects to an Artifacts repository to which you browse to the script in the script path window

No alt text provided for this image

The repository in this example is GitHub

No alt text provided for this image

The task configuration is then completed and saved.

No alt text provided for this image

The output from the script can be found in the logs of each deployment

No alt text provided for this image


No alt text provided for this image

Azure CLI follows a similar pattern and I use it where there a no PowerShell functions available (Who knows I might start creating some, just not yet) more reading can be found https://docs.microsoft.com/en-us/cli/azure/?view=azure-cli-latest

As with every journey this is just another step along the way, I'll leave this post with this finding, "script variables are your friend", and if I start that here will be hours more of typing and screenshots so will make that the next post very soon.

Paul Trotman

Paul Trotman