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 eliminates any need for physical shared storage just by mirroring internal flash and storage resources between hypervisor servers. Furthermore, the solution can be run on the off-the-shelf hardware. Such design allows VSAN from StarWind to not only achieve high performance and efficient hardware utilization but also reduce operational and capital expenses.
Find out more about ➡ VSAN from StarWind

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
24
Views Today
44
Appreciate how useful this article was to you?
No Ratings Yet
Loading...
Back to blog
The following two tabs change content below.