问题
How can I use a secret variable in my powershell script in my release definition?
I came across this but it doesn't work. The directory "$($env:AGENT_HOMEDIRECTORY)\agent\worker\Modules"
doesn't exist on the new agents.
What's the correct way of accessing a secret variable on new hosts? My agent version is 2.114.0.
回答1:
By design, you have to pass the value of secret variable through PowerShell parameters.
For example:
Variable: password (secret)
task: PowerShell
Arguments: -pass $(password)
Script:
Param(
[String]$pass
)
if ($pass) { Write-Host "variable is NOT null" }
if (!$pass) { Write-Host "variable is null" }
回答2:
You can achieve this now with-out the parameters, see my script below
Write-Host "Client Id " $env:client_id;
Write-Host "Client Secret" $(client_secret)
$applicationId = $env:client_id;
$clientsec = "$(client_secret)" | ConvertTo-SecureString -AsPlainText -Force
$credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $applicationId, $clientsec
来源:https://stackoverflow.com/questions/43047116/vsts-powershell-secret-variable