Azure DevOps Set Build number variable in a Build Task

荒凉一梦 提交于 2020-12-16 04:55:39

问题


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?


回答1:


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:

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.




回答2:


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



来源:https://stackoverflow.com/questions/58286114/azure-devops-set-build-number-variable-in-a-build-task

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!