gpt4 book ai didi

powershell - 无法读取 VSTS Online 发布变量

转载 作者:行者123 更新时间:2023-12-03 00:10:24 25 4
gpt4 key购买 nike

我正在使用 VSTS 环境变量,但一直使用 secret 类型的变量。
我正在使用 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)(使用 Hosted 2017 代理)。

但是,对于 issecret=true 变量,甚至对于手动创建的变量,我无法在发布部署过程中检索其值。

variables script release-error step-release

根据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 变量应该可供脚本(甚至代理阶段步骤)访问,尽管它们是 secret 的。

最佳答案

请引用以下步骤进行操作:

  1. 点击“库”选项卡
  2. 点击 + 变量组
  3. 指定变量组名称
  4. 启用 Azure Key Vault 的链接 secret 作为变量并链接 Azure Key Vault
  5. 点击“+添加”以添加必要的 secret
  6. 编辑发布定义
  7. 选择变量选项卡
  8. 选择变量组
  9. 单击“链接变量组”以链接该变量组
  10. 直接在发布任务中使用相关变量($(变量名))

关于powershell - 无法读取 VSTS Online 发布变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50353395/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com