I have this PowerShell script, that reads some environment variables and outputs them:
Write-Host "name: $(tenantName) version: $(versionRelease) url: $(urlApplication)"
Those variables are defined as pipeline variables and also in variable groups in an Azure DevOps release pipeline.
When run inside a PowerShell task defined as Inline, this script works as expected. However, the same exact script won't work when the PowerShell task is configured with a File Path. In this case, the tenantName
env variable is not found:
tenantName : The term 'tenantName' 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.
Is there any way to make the environment variables available to a "File" script as they are to an "Inline" one?
I managed to fix it, partially thanks to @Cbsch's answer. Indeed, the syntax of my PowerShell script was not correct, but changing $(tenantName)
to $tenantName
didn't fix the problem, since the $tenantName
didn't exist. I had to read it from the environment variables, with the $env:<variableName>
syntax.
The fixed script:
Write-Host "name: $env:tenantName version: $env:versionRelease url: $env:urlApplication"