4

I'm currently in the process of converting VSTS build pipelines to YAML build definions. However I can't yet find a way to use variables of a Variable Group within my YAML file. If I reference a variable, just like before within a build pipeline, the PowerShell script doesn't seem to be able to find it.

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

The detailed error message is as follows:

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'.

As you can see, I've already enabled system.debug for the build pipeline. So:

  • Is it already supported to use variable groups?
  • If yes, what is the way to reference those variables?
Anthon
  • 69,918
  • 32
  • 186
  • 246
Herman Cordes
  • 4,628
  • 9
  • 51
  • 87
  • Instead of using $(AzureSqlDb_DatabaseName), it also doesn't work when using $env:AzureSqlDb_DatabaseName. Although, no error appears in that case. – Herman Cordes Aug 21 '18 at 12:34
  • See also: https://stackoverflow.com/questions/52372291/azure-devops-vsts-link-variable-group-through-yaml?noredirect=1&lq=1 – Herman Cordes Nov 06 '18 at 12:33

1 Answers1

3

The solution was very simple. Just like with a normal build pipeline, you also need to link a variable group to the YAML build pipeline from the VSTS portal. The way to this is described here: Use a variable group.

Herman Cordes
  • 4,628
  • 9
  • 51
  • 87
  • 1
    For those of you that get stuck on this, the "Variables" tab in Azure DevOps is hidden behind the "Edit" link of the "Pipelines > Builds" screen. – Pat Sep 25 '18 at 15:46