I have a HelloWorld variable library in Azure DevOps containing the variable $foo=bar.
I want to read it in my pipeline using Get-Variable but regardless of the scope I give to my search, the variable is nowhere to be found. It is however, accessible "directly" (as shown below):
variables:
- group: HelloWorld
stages:
- stage: test
jobs:
- job:
displayName: Retrieve variables
steps:
- task: Powershell@2
displayName: Variable retrieval
inputs:
targetType: inline
verbose: true
script: |
# This works
Write-Host "Direct access: $(foo)"
# All of the following returns nothing
$indirectAccess = Get-Variable -Name "foo" -ValueOnly -ErrorAction SilentlyContinue
$indirectAccess = Get-Variable -Name "foo" -ValueOnly -ErrorAction SilentlyContinue -Scope Global
$indirectAccess = Get-Variable -Name "foo" -ValueOnly -ErrorAction SilentlyContinue -Scope Script
Write-Host "Indirect access: $indirectAccess"
Can I in any way retrieve library variables with Get-Variable?
The reason it's so important for me to know whether it's possible is because I need to retrieve values with variables which name is a variable itself... And so far I haven't found a way to do it except than with Get-Variable.