簡體   English   中英

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"

來自管道執行的示例 output:

connectionString: ***
password: Paw0rd

如果我按照以下@Thomas 的建議在管道任務中使用單引號:

示例 Powershell 任務:

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

來自管道執行的示例 output:

connectionString: ***
password: ***

@ShaykiAbramczyk 是正確的,秘密是不可見的。 然而,這些值在 Powershell 腳本中得到了正確使用。 我通過發布測試 output 文件並看到 KeyVault 值在 output 文件中驗證了這一點。 以下參考給了我發布以查看值的想法,而不是嘗試將它們回顯或寫入控制台。

在 Azure 管道中使用來自 Azure Key Vault 的機密

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM