bash - 在 Azure Devops 中,如何在 "Azure CLI task v.2"运行的 shell 脚本中使用管道变量?

标签 bash azure azure-devops azure-pipelines azure-cli

我正在尝试在 Azure Devops 中使用 Azure CLI 和 bash 执行任务。我正在使用 Azure CLI 任务 v.2 并选择 shell 作为脚本类型,如下所示。 enter image description here 我想在 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 脚本中的管道变量:

  1. (建议)将它们直接作为脚本中的环境变量读取。 Azure DevOps 管道变量添加为可由 bash 脚本访问的环境变量。因此,只需定义/设置管道变量,您就可以从 bash 脚本访问它们。即在您的脚本中将它们引用为 $OWNERNAME 和 $RGNAME。
    请参阅 > https://learn.microsoft.com/en-us/azure/devops/pipelines/process/variables#environment-variables

  2. 引用 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/

相关文章:

bash - 如何将 Jupyter Notebook (Windows) shell 更改为 bash

azure - 如何作为身份提供商从 ADFS 输出 B2C 中的组声明

azure - 通过 ARM 模板为服务连接用户分配角色

powershell - 如何将 AzureDevops 中的 Powershell 7 与 AWS 工具结合使用

Azure 上托管的 ASP.NET 网站在后台每 3-4 分钟进行一次身份验证

asp.net - Visual Studio Team Services 在构建期间编译 LESS 脚本

bash - 如何使用shell将一些不同大小的文件合并到一个excel文件中?

linux - 更好的 Linux shell?

linux - Bash 计算执行时间

asp.net - Azure Blob 存储 PUT 请求不返回结果代码