简体   繁体   中英

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. Even with double or single quotes surrounding the variables in the DevOps task, the values do not appear correct in the script.

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:

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

Sample values stored in 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:

connectionString: ***
password: Paw0rd

If I use single quotes in the pipeline task as suggested by @Thomas below:

Sample Powershell task:

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

Sample output from Pipeline execution:

connectionString: ***
password: ***

@ShaykiAbramczyk is correct, secrets are not viewable. The values are however being properly utilized in the Powershell script. I verified this by publishing a test output file and seeing that the KeyVault values are in the output file. 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM