【问题标题】:How to access VSTS Variable Groups from YAML build pipeline?如何从 YAML 构建管道访问 VSTS 变量组?
【发布时间】:2019-01-27 09:12:23
【问题描述】:

我目前正在将 VSTS 构建管道转换为 YAML build definions。但是我还没有找到在我的 YAML 文件中使用 Variable Group 变量的方法。如果我引用一个变量,就像之前在构建管道中一样,PowerShell 脚本似乎无法找到它。

- powershell: |
    Write-Output Testing...
    Write-Output "DatabaseName: $(AzureSqlDb_DatabaseName)"
  displayName: Output Library Vars

详细错误信息如下:

AzureSqlDb_DatabaseName : The term 'AzureSqlDb_DatabaseName' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At D:\a\_temp\e06f9ee7-8418-4339-a976-ed78a0e71021.ps1:3 char:31
+ Write-Output "DatabaseName: $(AzureSqlDb_DatabaseName)"
+                               ~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (AzureSqlDb_DatabaseName:String) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : CommandNotFoundException

##[debug]Exit code: 1
##[debug]Leaving Invoke-VstsTool.
##[error]PowerShell exited with code '1'.

如您所见,我已经为构建管道启用了 system.debug。所以:

  • 是否已经支持使用变量组?
  • 如果是,引用这些变量的方法是什么?

【问题讨论】:

  • 不使用 $(AzureSqlDb_DatabaseName),但在使用 $env:AzureSqlDb_DatabaseName 时也不起作用。虽然,在这种情况下不会出现错误。

标签: azure-devops azure-pipelines


【解决方案1】:

解决方案非常简单。就像使用普通构建管道一样,您还需要从 VSTS 门户将变量组链接到 YAML 构建管道。此处描述了此方法:Use a variable group

【讨论】:

  • 对于那些卡在这个问题上的人,Azure DevOps 中的“变量”选项卡隐藏在“管道 > 构建”屏幕的“编辑”链接后面。
猜你喜欢
  • 2021-05-12
  • 2020-11-07
  • 2019-10-04
  • 1970-01-01
  • 2020-08-11
  • 1970-01-01
  • 2021-08-31
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多