VSTS Powershell Secret Variable

不羁的心 提交于 2020-03-22 08:55:22

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!