AzureDevOps Powershell 任务命令行参数未在 Powershell 脚本中正确呈现
AzureDevOps Powershell task command line parameters are not properly rendered in Powershell script
我有一个 AzureDevops Powershell 任务,它将从 KeyVault 读取的值作为参数传递给脚本。即使在 DevOps 任务中用双引号或单引号括起变量,脚本中的值也不会正确显示。
我还需要做什么才能将这些值正确传递给脚本?
有一个,答案是双引号任务中的参数,我已经这样做了,但无济于事。
示例 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: ***
@ShaykiAbramczyk 是正确的,秘密是不可见的。然而,这些值在 Powershell 脚本中得到了正确使用。我通过发布测试输出文件并查看 KeyVault 值在输出文件中来验证这一点。以下参考给了我发布以查看值的想法,而不是尝试回显或将它们写入控制台。
我有一个 AzureDevops Powershell 任务,它将从 KeyVault 读取的值作为参数传递给脚本。即使在 DevOps 任务中用双引号或单引号括起变量,脚本中的值也不会正确显示。
我还需要做什么才能将这些值正确传递给脚本?
有一个
示例 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: ***
@ShaykiAbramczyk 是正确的,秘密是不可见的。然而,这些值在 Powershell 脚本中得到了正确使用。我通过发布测试输出文件并查看 KeyVault 值在输出文件中来验证这一点。以下参考给了我发布以查看值的想法,而不是尝试回显或将它们写入控制台。