Azure DevOps在生成任务中设置生成编号变量 [英] Azure DevOps Set Build number variable in a Build Task
问题描述
在Azure DevOps中,我创建了一个Build.在该版本中,我创建了一个ProjectBuildNumber Pipeline变量,该变量可以在队列时间设置.然后在选项"->内部版本号"格式下使用该变量来设置我在Azure中显示的内部版本号.
但是,我试图在我正在构建/部署的代码中使ProjectBuildNumber变量可设置.有没有一种方法可以让我的内部版本中有一个任务来更新该ProjectBuildNumber并更新Azure DevOps中的内部版本号?
有没有一种方法可以让我的版本中有一个任务来更新该ProjectBuildNumber并更新Azure DevOps中的内部版本号?
答案是是.
您可以在构建定义中添加一个 Inline Power-Shell
任务,以更新 ProjectBuildNumber
的值,然后在其基础上更新构建号:
写入主机"## vso [task.setvariable variable = ProjectBuildNumber;] YourUpdateValue"写主机"## vso [build.updatebuildnumber] xxx.$(ProjectBuildNumber).xxx.xxx"
检查
此外,如果要在 UI/Web门户上更新管道变量的值,则需要REST API(如何修改发布任务中的Azure DevOps发布定义变量?
注意:将API更改为构建定义:
PUT https://dev.azure.com/{organization}/{project}/_apis/build/definitions/{definitionId}?api-version=5.0
希望这会有所帮助.
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?
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.
这篇关于Azure DevOps在生成任务中设置生成编号变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!