简体   繁体   English

AzureDevOps Powershell 任务命令行参数在 Powershell 脚本中未正确呈现

[英]AzureDevOps Powershell task command line parameters are not properly rendered in Powershell script

I have an AzureDevops Powershell task which is passing values read from KeyVault as parameters to the script.我有一个 AzureDevops Powershell 任务,它将从 KeyVault 读取的值作为参数传递给脚本。 Even with double or single quotes surrounding the variables in the DevOps task, the values do not appear correct in the script.即使在 DevOps 任务中的变量周围使用双引号或单引号,脚本中的值也不正确。

What else do I need to do to get these values passed properly to the script?我还需要做什么才能将这些值正确传递给脚本?

There is an older similar question and the answer was to double-quote the parameters in the task, which I've done, to no avail.有一个较旧的类似问题,答案是双引号任务中的参数,我已经完成了,但无济于事。

Sample Powershell task:示例 Powershell 任务:

ScriptArguments: -connectionString "$(ConnString)" -password "$(ConnStringPassword)"

Sample values stored in KeyVault:存储在 KeyVault 中的示例值:

ConnString:  Server=tcp:test-sqldb.database.windows.net,1433;Initial Catalog=TestDb;Persist Security Info=False;
ConnStringPassword:  Pa$$w0rd

Sample Script:示例脚本:

param (
  [string]$connectionString,
  [string]$password
)

Write-Host "connectionString: $connectionString"
Write-Host "password: $password"

Sample output from pipeline execution:来自管道执行的示例 output:

connectionString: ***
password: Paw0rd

If I use single quotes in the pipeline task as suggested by @Thomas below:如果我按照以下@Thomas 的建议在管道任务中使用单引号:

Sample Powershell task:示例 Powershell 任务:

ScriptArguments: -connectionString '$(ConnString)' -password '$(ConnStringPassword)'

Sample output from Pipeline execution:来自管道执行的示例 output:

connectionString: ***
password: ***

@ShaykiAbramczyk is correct, secrets are not viewable. @ShaykiAbramczyk 是正确的,秘密是不可见的。 The values are however being properly utilized in the Powershell script.然而,这些值在 Powershell 脚本中得到了正确使用。 I verified this by publishing a test output file and seeing that the KeyVault values are in the output file.我通过发布测试 output 文件并看到 KeyVault 值在 output 文件中验证了这一点。 The following reference gave me the idea to publish to see the values as opposed to trying to echo or write them to the console.以下参考给了我发布以查看值的想法,而不是尝试将它们回显或写入控制台。

Use secrets from Azure Key Vault in Azure Pipelines 在 Azure 管道中使用来自 Azure Key Vault 的机密

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 脚本任务的 PowerShell 参数 - PowerShell parameters for script task PowerShell命令行参数和' - ' - PowerShell command line parameters and '--' 如何通过命令行或计划任务将数组参数传递给 powershell 脚本? - How to pass array parameters to a powershell script via command line or scheduled task? Powershell脚本任务output的AzureDevOps Pipeline变量赋值 - AzureDevOps Pipeline variable assignment of Powershell script task output PowerShell添加任务以使用参数运行PowerShell脚本 - PowerShell add Task to run PowerShell script with parameters Powershell 将脚本中的参数与在命令行中输入的参数组合在一起? - Powershell combine parameters inside a script with parameters entered on the command line? powershell参数命令行菜单 - powershell parameters command line menu 从命令行使用带引号的参数执行Powershell脚本 - Executing Powershell script from command line with quoted parameters 如何更改Powershell命令行以将mongodb导出到Powershell脚本中(用于计划任务) - How to alter powershell command line for mongodb export into a Powershell script (for scheduled task purposes) 在计划任务中将参数传递给 powershell 脚本 - Passing Parameters to powershell script in scheduled task
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM