0

I'm trying to get a variable value that lives in an Azure DevOps Library Group.

Normally, you would get it like this in, say, a PowerShell script of an Azure Pipeline job:

$(libraryVariableName)

However, I was wondering instead of the hard-coded value 'libaryVariableName' could I use a variable instead:

$testVarName = 'librayVariableName'
#then try to get the value like this:

$($testVarName)

But this doesn't work, it just prints out 'libraryVariableName' instead of the actual value

Rod
  • 14,529
  • 31
  • 118
  • 230
  • Please provide more details. What do you mean by "library variable name"? What are you trying to do? – Daniel Mann Apr 25 '23 at 21:16
  • 1
    maybe `Get-Variable $testVarName -ValueOnly` is what you're looking for? – Santiago Squarzon Apr 25 '23 at 21:38
  • If you're looking for a solution _in PowerShell code_, see the next comment. However, this won't work you're looking for a solution at the level of an _Azure macro_ (`$()`), which has nothing to do with PowerShell per se. – mklement0 Apr 25 '23 at 21:49
  • For _variable indirection_ in PowerShell, where you refer to a variable _indirectly_, via its name stored in a different variable or provided by an expression, use the [`Get-Variable`](https://docs.microsoft.com/powershell/module/microsoft.powershell.utility/get-variable) and [`Set-Variable`](https://docs.microsoft.com/powershell/module/microsoft.powershell.utility/set-variable) cmdlets, but note that there are usually better alternatives, such as hashtables. – mklement0 Apr 25 '23 at 21:50

0 Answers0