无法读取 VSTS Online 发布变量
Unable to read VSTS Online release variables
我正在使用 VSTS 环境变量并坚持使用秘密类型的变量。
我正在使用 POSH 脚本(文件)生成变量(实际上,是从 Azure Key Vault 获取值并将该值设置为变量):
#在发布步骤中添加为脚本参数
-ResourceGroupNameArg "$(ResourceGroupName)" -KeyVaultNameArg "$(KeyVaultName)" -KeyVaultSecretNameArg "$(KeyVaultSecretName)"
#脚本本身
Param(
[string]$ResourceGroupNameArg,
[string]$KeyVaultNameArg,
[string]$KeyVaultSecretNameArg
)
<...>
$secret = Get-AzureKeyVaultSecret -VaultName $KeyVaultNameArg -Name $KeyVaultSecretNameArg
$secretValue = $secret.SecretValueText
Write-Host "##vso[task.setvariable variable=SQLAdministratorPassword;issecret=true]$secretValue"
在这里,我可以将不同的 KeyVault 名称传递给脚本(根据我的需要)- 通过替换 $KeyVaultNameArg 和 $KeyVaultSecretNameArg 变量。
对于使用 ##vso[task.setvariable variable=
配置的任何其他变量,我可以使用构造 $env:DatabaseName
(例如在另一个 POSH 脚本中)或代理阶段步骤中的 $(DatabaseName)
来检索它们(使用托管2017代理)。
但是,对于 issecret=true
变量甚至是手动创建的变量,我无法在发布部署过程中检索其值。
根据 this 文章,
The values of hidden (secret) variables are stored securely on the
server and cannot be viewed by users after they are saved. During a
deployment, the Release Management service decrypts these values when
referenced by the tasks and passes them to the agent over a secure
HTTPS channel.
因此 IMO 变量应该可供脚本(甚至代理阶段步骤)访问,尽管它们是秘密的。
参考以下步骤完成:
- 单击库选项卡
- 点击+变量组
- 指定变量组名称
- 为 Azure 密钥保管库启用 Link 机密作为变量和 link Azure 密钥保管库
- 点击“+添加”添加必要的密码
- 编辑版本定义
- 选择变量选项卡
- Select 变量组
- 点击Link变量组到link那个变量组
- 在发布任务中直接使用相关变量(
$(variable name)
)
我正在使用 VSTS 环境变量并坚持使用秘密类型的变量。
我正在使用 POSH 脚本(文件)生成变量(实际上,是从 Azure Key Vault 获取值并将该值设置为变量):
#在发布步骤中添加为脚本参数
-ResourceGroupNameArg "$(ResourceGroupName)" -KeyVaultNameArg "$(KeyVaultName)" -KeyVaultSecretNameArg "$(KeyVaultSecretName)"
#脚本本身
Param(
[string]$ResourceGroupNameArg,
[string]$KeyVaultNameArg,
[string]$KeyVaultSecretNameArg
)
<...>
$secret = Get-AzureKeyVaultSecret -VaultName $KeyVaultNameArg -Name $KeyVaultSecretNameArg
$secretValue = $secret.SecretValueText
Write-Host "##vso[task.setvariable variable=SQLAdministratorPassword;issecret=true]$secretValue"
在这里,我可以将不同的 KeyVault 名称传递给脚本(根据我的需要)- 通过替换 $KeyVaultNameArg 和 $KeyVaultSecretNameArg 变量。
对于使用 ##vso[task.setvariable variable=
配置的任何其他变量,我可以使用构造 $env:DatabaseName
(例如在另一个 POSH 脚本中)或代理阶段步骤中的 $(DatabaseName)
来检索它们(使用托管2017代理)。
但是,对于 issecret=true
变量甚至是手动创建的变量,我无法在发布部署过程中检索其值。
根据 this 文章,
The values of hidden (secret) variables are stored securely on the server and cannot be viewed by users after they are saved. During a deployment, the Release Management service decrypts these values when referenced by the tasks and passes them to the agent over a secure HTTPS channel.
因此 IMO 变量应该可供脚本(甚至代理阶段步骤)访问,尽管它们是秘密的。
参考以下步骤完成:
- 单击库选项卡
- 点击+变量组
- 指定变量组名称
- 为 Azure 密钥保管库启用 Link 机密作为变量和 link Azure 密钥保管库
- 点击“+添加”添加必要的密码
- 编辑版本定义
- 选择变量选项卡
- Select 变量组
- 点击Link变量组到link那个变量组
- 在发布任务中直接使用相关变量(
$(variable name)
)