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

VSAN from StarWind is software-defined storage (SDS) solution created with restricted budgets and maximum output in mind. It pulls close to 100% of IOPS from existing hardware, ensures high uptime and fault tolerance starting with just two nodes. StarWind VSAN is hypervisor and hardware agnostic, allowing you to forget about hardware restrictions and crazy expensive physical shared storage.

Build your infrastructure with off-the-shelf hardware, scale however you like, increase return on investment (ROI) and enjoy Enterprise-grade virtualization features and benefits at SMB price today!


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

Views All Time
3
Views Today
24
Back to blog
The following two tabs change content below.
Nicolas Prigent
Nicolas Prigent
Nicolas Prigent works as an IT Production Manager, based in Paris, with a primary focus on Microsoft technologies. Nicolas is a three-time Microsoft MVP in Cloud and Datacenter Management with 10 years experience in administering Windows products. He also received the "PowerShell Heroes 2016" Award.