Home > OS >  How to access Azure DevOps Predefined variables from Powershell script file
How to access Azure DevOps Predefined variables from Powershell script file

Time:02-17

I have a Powershell script which I run in an ADO release stage via the Powershell Task file path method (the ps1 file is in my wwwroot/scripts folder).

In the Powershell script, I need to access the Build.BuildId to do some work, however, it's blowing up on that variable wherein before when I ran this code via the "inline" method, it worked fine.

I cannot run the script "inline" as we have this script doing a lot of things and it exceeds the Powershell Task inline script character limit.

How can I access the Build.BuildId variable from the file?

 Build.BuildId : The term 'Build.BuildId' is not recognized as the name of a cmdlet, function, script file, or operable 
2022-02-16T18:58:30.4256566Z program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
2022-02-16T18:58:30.4257898Z At D:\_agent1\_work\r11\a\...\wwwroot\scripts\myscript.ps1:70 char:90
2022-02-16T18:58:30.4259534Z   ...$project/_apis/build/builds/$(Build.BuildId)/workit ...

CodePudding user response:

The name is upper-cased, and the . is replaced with the _

  • PowerShell script: $env:VARIABLE_NAME $env:BUILD_BUILDID

REF: https://docs.microsoft.com/en-us/azure/devops/pipelines/process/variables?view=azure-devops&tabs=yaml,batch#environment-variables

  • Related