VSTS Powershell秘密变量

Mar*_*oxx 3 powershell azure-pipelines azure-pipelines-release-pipeline azure-devops-rest-api

如何在我的版本定义中的powershell脚本中使用秘密变量?

我遇到过这个,但它不起作用."$($env:AGENT_HOMEDIRECTORY)\agent\worker\Modules"新代理上不存在该目录.

在新主机上访问秘密变量的正确方法是什么?我的代理版本是2.114.0.

sta*_*SFT 7

按照设计,您必须通过PowerShell参数传递secret变量的值.

例如:

变量: password (secret)

任务: PowerShell

参数: -pass $(password)

脚本:

Param(
 [String]$pass
)
if ($pass) { Write-Host "variable is NOT null" }
if (!$pass) { Write-Host "variable is null" }
Run Code Online (Sandbox Code Playgroud)

  • @Mardoxx 不,您需要将其作为参数传递。https://github.com/Microsoft/vsts-agent/issues/145 (2认同)
  • 注意:应该是`[SecureString]` 而不是`[string]`。https://github.com/PowerShell/PSScriptAnalyzer/blob/development/RuleDocumentation/AvoidUsingPlainTextForPassword.md (2认同)
  • 使用内联PowerShell脚本时,出现错误:`Param:术语'Param'不被识别为cmdlet,函数,脚本文件或可操作程序的名称。 (2认同)