4
votes

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?
1
Instead of using $(AzureSqlDb_DatabaseName), it also doesn't work when using $env:AzureSqlDb_DatabaseName. Although, no error appears in that case.Herman Cordes

1 Answers

3
votes

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.