如何在不创建任务组参数的情况下在任务组中使用密钥保管库机密

How to Use a Key Vault Secret in a Task Group Without Creating a Task Group Parameter

我在 Azure DevOps 中有一个任务组执行以下任务(以及其他任务):

1 - 从 Key Vault 读取机密

2 - Set/Update 应用程序设置为密钥保管库中的机密

[
   {
    "name": "Foo",
    "value": "$(FooKeyVaultKey)",
    "slotSetting": false
   }
]

鉴于上述任务,我在任务组中想要的唯一参数是从中获取机密的密钥保管库的名称。问题是,由于第二个任务使用了一个变量(由任务 1 设置),任务组创建了一个名为“FooKeyVaultKey”的新参数。

我尝试以不同的方式访问变量,但只有使用括号才有效。

$(FooKeyVaultKey) - works, but creates parameter
${{FooKeyVaultKey}} - doesn't work
${FooKeyVaultKey} - doesn't work
$[FooKeyVaultKey] - doesn't work

这是不可能实现的。这是写在the documentation

All the '$(vars)' from the underlying tasks, excluding the predefined variables, will surface as the mandatory parameters for the newly created task group.

For example, let's say you have a task input $(foobar), which you don't intend to parameterize. However, when you create a task group, the task input is converted into task group parameter 'foobar'. Now, you can provide the default value for the task group parameter 'foobar' as $(foobar). This ensures that at runtime, the expanded task gets the same input it's intended to.

简单的技巧是在变量表达式中嵌套一个空白表达式(微软称之为宏语法):

$($()foo)

这样就不会为任务组创建参数。

编辑: 我注意到一些不一致的行为,有时应用程序配置会被设置为 $($()foo).