如何在Azure DevOps中将参数传递给Azure CLI任务?
How do you pass a parameter to an Azure CLI Task in Azure DevOps?
以非常基本的示例显示有关VM的基本信息.一个基本的CLI命令将是:
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?
我尝试将CLI任务创建为嵌入式脚本和文件,并使用Azure DevOps Argument构建器传递参数,但似乎无济于事.参数如下所示:
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"
在脚本中,无论尝试如何,都无法获得-vmname参数.我尝试过:
In the script, I can't get the -vmname parameter, no matter what I try. I've tried:
- $ 1
- $ vmname
- %vmname
- %vmname%
那我该怎么办?
推荐答案要使用构建变量,可以使用 $(var_name)表示法,因此在内联脚本中应使用以下内容:
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如果要启动脚本,则将使用相同的方法.如果您实际上是在谈论如何在bash脚本中获取参数,则第一个参数应该为$ 1(据我记得)
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)
更多推荐
将参数传递给DevOps中的Azure CLI任务
发布评论