Description/Question: I have an Azure DevOps Classic Release pipeline where I need to use variables from either pipeline variables or variable groups in my PowerShell scripts.
Expected Behavior:
Variables defined in the pipeline or variable groups should be available to my scripts, whether I am using an inline PowerShell task or referencing a .ps1 script file from source control.
Actual Behavior:
When I use an inline PowerShell task (script entered directly in the task UI), I can access pipeline and variable group variables using the $(VariableName) syntax, and it works as expected (even for secrets, which are masked in logs).
When I use a PowerShell script file (.ps1) from source control, the same variables are not available—even when I try to access them as $env:VariableName or ${env:variable-with-dash}.
Dumping the environment variables at runtime (Get-ChildItem env:) confirms the variables are missing.
Only a small subset of built-in and agent variables are present.
Sample Repro Steps:
Create a variable in the pipeline or variable group, e.g., MySecretVar. In an inline PowerShell task This works as expected.
Write-Host "Value is: $(MySecretVar)"
In a .ps1 script file PowerShell this outputs nothing i.e. the variable is not available.
Write-Host "Value is: $env:MySecretVar"
Question:
Is this the expected behavior in Azure DevOps? Is there a documented way to make pipeline or variable group variables reliably available to .ps1 script files?
If not, what is the recommended approach for sharing variables between pipeline and script files?
Has anyone found a workaround for this limitation?
What I’ve Tried:
Using both $env:VariableName and ${env:variable-with-dash} syntax in script files.
Declaring variables at pipeline, stage, and job level.
Using classic and YAML pipelines.
Dumping all environment variables to confirm their absence.
Environment:
Azure DevOps Services (cloud)
PowerShell 5.1 and 7.x

