gpt4 book ai didi

azure-devops - 如何在 vsts 发布任务中使用 secret 变量?

转载 作者:行者123 更新时间:2023-12-01 00:25:08 25 4
gpt4 key购买 nike

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

使用密码的powershell任务的定义

Task definition

关联变量组

Variable definition

错误输出:

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.

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

这是我的 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)

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])"

enter image description here
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:

与单引号相同
enter image description here
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:

最佳答案

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

  • 拥有 .以变​​量组中的 secret 变量的名义
    不起作用。我在单独的版本中重新创建了这个问题
    定义/变量组。
  • 即使在我删除 .在我的 var
    我仍然必须重新创建变量组才能使其工作。

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

    关于azure-devops - 如何在 vsts 发布任务中使用 secret 变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45593094/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com