将参数传递给DevOps中的Azure CLI任务

编程入门 行业动态 更新时间:2024-10-12 22:27:32
本文介绍了将参数传递给DevOps中的Azure CLI任务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

如何在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任务

本文发布于:2023-11-24 02:20:24,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1623614.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:参数   DevOps   CLI   Azure

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!