1
votes

In Azure DevOps, I created a Build. In that Build I created a ProjectBuildNumber Pipeline variable that is Settable at queue time. That variable is then used under Options -> Build number format to set my build number displayed in Azure.

However, I am trying to make that ProjectBuildNumber variable settable in the code I am building/deploying. Is there a way I can have a Task in my Build to update that ProjectBuildNumber and update the Build number in Azure DevOps?

3

3 Answers

5
votes

Is there a way I can have a Task in my Build to update that ProjectBuildNumber and update the Build number in Azure DevOps?

The answer is yes.

You could add a Inline Power-Shell task in your build definition to update the value of ProjectBuildNumber and then update the build number base on the it:

Write-Host "##vso[task.setvariable variable=ProjectBuildNumber;]YourUpdateValue"

Write-Host "##vso[build.updatebuildnumber]xxx.$(ProjectBuildNumber).xxx.xxx"

Check the Logging Command during the build for some more details:

enter image description here

Besides, if you want to update the value of a Pipeline Variable on the UI/web portal, you need the REST API (Definitions - Update) to update the value of the build pipeline definition variable from a build task.

There is a very similar thread, you can check the answer for the details:

How to modify Azure DevOps release definition variable from a release task?

Note:Change the API to the build definitions:

PUT https://dev.azure.com/{organization}/{project}/_apis/build/definitions/{definitionId}?api-version=5.0

Hope this helps.

0
votes

We can update Build Number in Azure Devops via two ways . One from Option Section/Tab and 2nd Via PowerShell Scripts.

To update the build number from Power shell Script.. We need to add following script..

Write-Host "##vso[build.updatebuildnumber]$(VersionNumber).$(VersionRevision)"

Here we have used 2 variables : VersionNumber and VersionRevision. We need to add 2 variables in PipeLine Configurations.. VersionNumber will be the desired number and VersionRevision is the counter number that will be updated every time, when ever we will create a new build. Please check the complete demonstration from You tube video

https://youtu.be/WBmFTmzopiQ

-1
votes

Check out the Microsoft documentation on this: Variables

Depending on your operating system you can add a Powershell/Batch/Bash Task and change the variable.

Edit: After some research it appears that the change of the variable will show up in the following task. Take a look at this issue Update environment variables using task.setvariable in a bash script does not work