我正在尝试在 Azure Devops 中使用 Azure CLI 和 bash 执行任务。我正在使用 Azure CLI 任务 v.2 并选择 shell 作为脚本类型,如下所示。 我想在 bash 脚本中使用管道变量。我在脚本中运行以下命令:
#!/bin/bash
az role assignment create --role "Lab Admin" --assignee $(ownerEmail) -g $(rgName)
我收到以下错误:
line 2: ownerEmail: command not found
line 2: rgName: command not found
我不明白。通常,我应该能够在 bash 脚本中使用 azure cli。 有人有想法吗?
最佳答案
有几种方法可以读取 bash 脚本中的管道变量:
(建议)将它们直接作为脚本中的环境变量读取。 Azure DevOps 管道变量添加为可由 bash 脚本访问的环境变量。因此,只需定义/设置管道变量,您就可以从 bash 脚本访问它们。即在您的脚本中将它们引用为 $OWNERNAME 和 $RGNAME。
请参阅 > https://learn.microsoft.com/en-us/azure/devops/pipelines/process/variables#environment-variables引用 bash 脚本中的直接参数。 Bash 参数是编号的并且可以这样引用。例如,对于您的 aruments,$1 是字符串“-labOwner”$2 是ownerEmail 管道变量中包含的值。
请参阅 > https://tecadmin.net/tutorial/bash-scripting/bash-command-arguments/
关于bash - 在 Azure Devops 中,如何在 "Azure CLI task v.2"运行的 shell 脚本中使用管道变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62153318/