我有一个 AzureDevops Powershell 任务,它将从 KeyVault 读取的值作为参数传递给脚本。即使在 DevOps 任务中使用双引号或单引号将变量括起来,脚本中的值也不会显示正确。
我还需要做什么才能将这些值正确传递给脚本?
有一个 older similar question,答案是双引号任务中的参数,我已经这样做了,但无济于事。
示例 Powershell 任务:
ScriptArguments: -connectionString "$(ConnString)" -password "$(ConnStringPassword)"
存储在 KeyVault 中的示例值:
ConnString: Server=tcp:test-sqldb.database.windows.net,1433;Initial Catalog=TestDb;Persist Security Info=False;
ConnStringPassword: Pa$$w0rd
示例脚本:
param (
[string]$connectionString,
[string]$password
)
Write-Host "connectionString: $connectionString"
Write-Host "password: $password"
管道执行的示例输出:
connectionString: ***
password: Paw0rd
如果我按照下面@Thomas 的建议在管道任务中使用单引号:
示例 Powershell 任务:
ScriptArguments: -connectionString '$(ConnString)' -password '$(ConnStringPassword)'
流水线执行的示例输出:
connectionString: ***
password: ***
答案 0 :(得分:0)
@ShaykiAbramczyk 是正确的,秘密是不可见的。然而,这些值在 Powershell 脚本中得到了正确利用。我通过发布测试输出文件并查看 KeyVault 值在输出文件中来验证这一点。以下参考资料让我想到了发布以查看值,而不是尝试回显或将它们写入控制台。