11

How do you pass a parameter to an Azure CLI Task in Azure DevOps?

Take the very basic example of showing basic info about a VM. A basic CLI command would be:

  • az vm show --name myVM --resource-group dev -o table

Now if I wanted to parameterize that command, so that I could pass in the VM Name, who would i do it?

I've tried creating a CLI Task as both an in-line script and a file, passing parameters using the Azure DevOps Argument builder, but nothing seems to work. The parameter looks like this:

  • -vmname "win10-vs"

In the script, I can't get the -vmname parameter, no matter what I try. I've tried:

  • $1
  • $vmname
  • %vmname
  • %vmname%

So how do I do it?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
marlinspike
  • 185
  • 2
  • 2
  • 11

2 Answers2

6

to use build variables you can use the $(var_name) notation, so in your inline script you would use the following:

az vm show --name $(my_variable) --resource-group dev -o table

if you would launch the script you'd use the same approach. if you are actually talking about how to get parameters in bash script, it should be $1 for the first parameter (as far as I recall)

4c74356b41
  • 69,186
  • 6
  • 100
  • 141
0

Try passing the parameters in "Environment Variables" instead of "Script Arguments"

Inside your script use $myParameter

By the way, I tried what was mentioned in the answer but it didn't work for me. I'm running a Shell script on a windows host using Azure CLI Task 2.*

Fadi
  • 55
  • 1
  • 10