Search
StarWind is a hyperconverged (HCI) vendor with focus on Enterprise ROBO, SMB & Edge

Using PowerShell Tasks and Parameters in Azure DevOps Pipelines

  • December 17, 2020
  • 5 min read
IT Production Manager. Nicolas is primarily focused on Microsoft technologies, he is a Microsoft MVP in Cloud and Datacenter Management.
IT Production Manager. Nicolas is primarily focused on Microsoft technologies, he is a Microsoft MVP in Cloud and Datacenter Management.


Azure DevOps Services | Microsoft Azure

Azure DevOps is a powerful tool for any organization. Thanks to Azure DevOps you can perform a lot of admin tasks. For instance, you can quickly deploy applications to various Azure services such as Virtual Machines.

Sometimes, in the Release Pipelines, you might need to add PowerShell Tasks. In these PowerShell Tasks, you might also need to pass arguments to your script, so in this article, I will describe how to pass arguments in Release Azure DevOps PowerShell Tasks.

Deploying Azure DevOps Pipeline

First, we have to create a sample PowerShell script that will be stored in our Azure DevOps repository. This script will be used in the release task as “PowerShell Task”.

This script is a simple script that will create a Confluence space using Atlassian REST API, but you can create a script to perform any task you want.

Confluence space

The important thing to do is to include the following code at the beginning of your script:

Thanks to the CmdletBinding, you will be able to add [Parameter()] decorators to parameters (more information here: https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_functions_cmdletbindingattribute?view=powershell-7.1)

At this step, you must confirm that your script runs smoothly locally. Then, you can create your pipeline and add the variables you need. Go to the Variables tab and click Add

Add the variables

In my case, I need to create 5 variables because I need to pass 5 arguments to the script. The name of the variables can be the same between your script and the pipeline but it is not mandatory. Now, go to “Tasks” and click “+”, then search “PowerShell” and click “Add

Add tasks

Browse the repository and select your PowerShell script. In the arguments field, add the following code:

  • “ScriptArg1” is the argument you write at the beginning of your script
  • “PipelineArg1” is the variable you create in the pipeline

ScriptArg1

Once it’s ok, you can save and create the release.

Create the release

Wait until the release has been created.

Release process

Click Deploy to run the task and confirm that the variables are passed to the script.

Deploy to run the task

To confirm the result, go to Logs and check the status.

Agent job / Check the status

Found Nicolas’s article helpful? Looking for a reliable, high-performance, and cost-effective shared storage solution for your production cluster?
Dmytro Malynka
Dmytro Malynka StarWind Virtual SAN Product Manager
We’ve got you covered! StarWind Virtual SAN (VSAN) is specifically designed to provide highly-available shared storage for Hyper-V, vSphere, and KVM clusters. With StarWind VSAN, simplicity is key: utilize the local disks of your hypervisor hosts and create shared HA storage for your VMs. Interested in learning more? Book a short StarWind VSAN demo now and see it in action!