Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to access Azure DevOps Predefined variables from Powershell script file

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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 ...

>Solution :

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%2Cbatch#environment-variables

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading