Azure DevOps 在构建任务中设置构建编号变量 [英] Azure DevOps Set Build number variable in a Build Task

查看:49
本文介绍了Azure DevOps 在构建任务中设置构建编号变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Azure DevOps 中,我创建了一个 Build.在那个构建中,我创建了一个在排队时可设置的 ProjectBuildNumber 管道变量.然后在选项 -> 内部版本号格式下使用该变量来设置我在 Azure 中显示的内部版本号.

但是,我试图在我正在构建/部署的代码中设置该 ProjectBuildNumber 变量.有没有办法让我的 Build 中有一个 Task 来更新 ProjectBuildNumber 并更新 Azure DevOps 中的 Build 号?

解决方案

有没有办法让我的 Build 中有一个 Task 来更新 ProjectBuildNumber 并更新 Azure DevOps 中的 Build 号?

答案是.

您可以在构建定义中添加一个 Inline Power-Shell 任务来更新 ProjectBuildNumber 的值,然后根据它更新构建号:

Write-Host "##vso[task.setvariable variable=ProjectBuildNumber;]YourUpdateValue"写主机##vso[build.updatebuildnumber]xxx.$(ProjectBuildNumber).xxx.xxx"

检查

此外,如果您想在UI/网络门户上更新管道变量的值,您需要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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆