VSTS Powershell Secret Variable

Mardoxx picture Mardoxx · Mar 27, 2017 · Viewed 8k times · Source

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.

Answer

starian chen-MSFT picture starian chen-MSFT · Mar 28, 2017

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" }