如何在 vsts 发布任务中使用秘密变量?

ssl*_*oan 4 azure-devops

我在 vsts 中有一个发布定义,需要访问我在变量组中定义为秘密变量的密码。我已将该组链接到此发布定义,但是当我运行任务时,参数最终为空。我需要做什么特别的事情来获取秘密变量的值吗?

使用密码的powershell任务的定义

任务定义

关联变量组

变量定义

错误输出:

2017-08-09T14:01:17.9262375Z ##[command].            'C:\agent_work\r1\a\$(AGENT.BUILDDIRECTORY)\RCV\deploys\common\Get-FromArtifactory.ps1' -repoUsername developer -repoPassword  -repoPath libs-snapshot-local
2017-08-09T14:01:18.8168538Z ##[error]C:\agent_work\r1\a\$(AGENT.BUILDDIRECTORY)\RCV\deploys\common\Get-FromArtifactory.ps1 : Missing an argument for parameter 'repoPassword'. Specify a parameter of type 'System.String' and try again.
Run Code Online (Sandbox Code Playgroud)

编辑以根据要求添加更多信息。

这是我的 Get-FromArtifactory.ps1 的开始

[CmdletBinding()]
param (
    [Parameter(Mandatory)]
    [String]
    $repoUsername,

    [Parameter()]
    [String]
    $repoPassword,

    # Other params
)
#setup credentials object for arty access
$secPassword = $repoPassword | ConvertTo-SecureString -asPlainText -Force
$credential = New-Object System.Management.Automation.PSCredential($repoUsername, $secPassword)
Run Code Online (Sandbox Code Playgroud)

2017 年 8 月 15 日编辑 - 我已将其更新为使用 @Marina-MSFT 建议的引号,但它仍然只是空白。

修改脚本以打印出部分密码:

[CmdletBinding()]
param (
    [Parameter(Mandatory)]
    [String]
    $repoUsername,

    [Parameter()]
    [String]
    $repoPassword,

#other params
)
write-host "pword $repoPassword"
write-host "1st char: $($repoPassword[0])"
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

2017-08-15T09:23:00.8606081Z ##[command]. 'C:\agent_work\r1\a\RCV\deploys\common\Get-FromArtifactory.ps1' -repoUsername developer -repoPassword "" -repoPath libs-snapshot-local -artifactName ipo-deposit-accounts_2.11 -artifactPath uk/gov/ipo -artifactVersion 0.1-SNAPSHOT -downloadDir C:\agent_work\r1\a
2017-08-15T09:23:02.3606174Z pword     
2017-08-15T09:23:02.3606174Z 1st char: 
Run Code Online (Sandbox Code Playgroud)

与单引号相同 在此处输入图片说明

2017-08-15T09:22:10.6573655Z ##[command]. 'C:\agent_work\r1\a\RCV\deploys\common\Get-FromArtifactory.ps1' -repoUsername developer -repoPassword '' -repoPath libs-snapshot-local -artifactName ipo-deposit-accounts_2.11 -artifactPath uk/gov/ipo -artifactVersion 0.1-SNAPSHOT -downloadDir C:\agent_work\r1\a
2017-08-15T09:22:11.2198723Z pword 
2017-08-15T09:22:11.3761178Z 1st char: 
Run Code Online (Sandbox Code Playgroud)

ssl*_*oan 5

我现在已经开始工作了,发生了两件事。

  1. 拥有 . 变量组中的秘密变量的名称不起作用。我在单独的发布定义/变量组中重新创建了这个问题。
  2. 即使在我删除 . 在我的 var 名称中,我仍然必须重新创建变量组才能使其工作。

问题的错误。在这里提出的变量名称:https : //developercommunity.visualstudio.com/content/problem/94475/secret-variable-in-variable-not-group-not-availabl.html