通过使用本网站, 您同意 隐私政策.
接受
进入IT进入IT进入IT
  • 家
  • 信息技术专家
  • 技术
  • 微软
    • 天蓝色
    • 配置管理器/SCCM
    • 数字PM
    • 协调者
    • Hyper-V
    • 微软 Edge 预览体验
    • 微星指数
    • 办公室 365
    • 办公室内幕
    • 电力商业智能
    • Skype
    • SQL服务器
    • 团队
  • 视窗
    • Windows 管理中心
    • Windows客户端
    • Windows服务器
  • SCCM查询集合列表
阅读: 创建新的 Azure DevOps 版本并使用 REST API 更新其变量
字体调整器氨基酸
进入IT进入IT
字体调整器氨基酸
  • 家
  • 信息技术专家
  • 技术
  • 微软
  • 视窗
  • SCCM查询集合列表
搜索
  • 家
  • 信息技术专家
  • 技术
  • 微软
    • 天蓝色
    • 配置管理器/SCCM
    • 数字PM
    • 协调者
    • Hyper-V
    • 微软 Edge 预览体验
    • 微星指数
    • 办公室 365
    • 办公室内幕
    • 电力商业智能
    • Skype
    • SQL服务器
    • 团队
  • 视窗
    • Windows 管理中心
    • Windows客户端
    • Windows服务器
  • SCCM查询集合列表
Azure DevOps

创建新的 Azure DevOps 版本并使用 REST API 更新其变量

出版: 二月 19, 2024
4 最小阅读量
分享

创建新的 Azure DevOps 版本并使用 REST API 更新其变量.

Azure DevOps is a comprehensive suite of development tools and services designed to help teams build and ship software faster and more efficiently. One of the key features of Azure DevOps is its build system, which allows teams to automate the build, test, and deployment process of their software.

在本文中, we will explore how to create a new Azure DevOps build and update its variables using REST API. We will use a sample code snippet that demonstrates how to create a new build using cURL, but you can use any programming language that supports REST API calls.

The first step in creating a new Azure DevOps build is to define its properties, such as the build definition and the build parameters. The build definition defines the build steps, which can include tasks like compiling code, running tests, and creating artifacts. The build parameters are variables that are used by the build steps to customize the build process.

To create a new build using REST API, you need to send a POST request to the Azure DevOps API endpoint that creates builds. The following code snippet demonstrates how to create a new build using cURL:

curl -X POST "https://dev.azure.com/{organization}/{project}/_apis/build/builds?api-version=7.0" \
-H "Content-Type: application/json" \
-d '{
    "definition": {
        "id": {definition_id}
    },
    "parameters": "{\"{parameter_name}\":\"{parameter_value}\"}"
}'

Working example with PAT:

curl -X POST "https://{username}:{PAT}@dev.azure.com/{organization}/{project}/_apis/build/builds?api-version=7.0" \
-H "Content-Type: application/json" \
-d '{
    "definition": {
        "id": {definition_id}
    },
    "parameters": "{\"{parameter_name}\":\"{parameter_value}\"}"
}'

Let’s break down this code snippet:

  • 这 -X POST flag specifies that we want to send a POST request.
  • The API endpoint for creating builds is https://dev.azure.com/{organization}/{project}/_apis/build/builds?api-version=7.0, where {organization} is the name of your Azure DevOps organization and {project} is the name of your project. 这 api-version parameter specifies the version of the API we want to use.
  • 这 -H "Content-Type: application/json" flag specifies that we are sending JSON data in the request body.
  • The request body is a JSON object that contains the following properties:
    • definition: an object that specifies the build definition. 这 id property specifies the ID of the build definition.
    • parameters: a JSON-formatted string that specifies the build parameters. 这 {parameter_name} 和 {parameter_value} placeholders should be replaced with the actual parameter name and value, 分别.

In the example code snippet, we are creating a new build using the build definition with ID 15 and updating its NUMBER_OF_WORKERS parameter with the value of a variable 2_NUMBER_OF_WORKERS, which can be replaced with an actual value at runtime. We are also setting the NUMBER_OF_WORKERS2 parameter to a static value of 5.

To update a build variable using REST API, you need to send a PATCH request to the API endpoint that updates build variables. The following code snippet demonstrates how to update a build variable using cURL:

curl -X PATCH "https://dev.azure.com/{organization}/{project}/_apis/build/builds/{build_id}/variables?api-version=7.0" \
-H "Content-Type: application/json" \
-d '{
    "variables": {
        "{variable_name}": {
            "value": "{new_value}"
        }
    }
}'

Let’s break down this code snippet:

  • 这 -X PATCH flag specifies that we want to send a PATCH request.
  • The API endpoint for updating build variables is `https://dev.azure.com/{organization}/{project}/_apis/build/builds/{build_id}/variables?api-version=7.0
标记:应用程序编程接口Azure DevOps重击CI/CDcurlJSON微软Azure
上一篇 Ubuntu 顺利升级 18 到Ubuntu 20
下一篇 在Almalinux中激活EPEL和EPEL Next 9 或洛基Linux 9 在Almalinux中激活EPEL和EPEL Next 9 或洛基Linux 9
发表评论 发表评论

发表回复 取消回复

您的电子邮件地址不会被公开. 必填字段已标记 *

该网站使用 Akismet 来减少垃圾邮件. 了解您的评论数据的处理方式.

翻译

English中文(简体)DanskNederlandsFrançaisDeutschItaliano한국어PolskiPortuguêsRomânăEspañolУкраїнська
经过 Transposh - translation plugin for wordpress

热门帖子

Windows Server 的系统要求 2016
Windows服务器
配置管理器查询集合列表
配置管理器查询集合列表
configmgr
在经典团队网站的新式页面上启用结构化/托管导航
技术
SCCM 无法从 MP 获取预期版本的 DP 位置
configmgr

最近的帖子

在 Ubuntu 上安装和配置 Fail2ban 以实现 SSH 保护 24.04
Linux
在AlmaLinux上启用和配置FirewallD
Linux
AlmaLinux中的用户创建和SSH密钥设置
Linux
如何在AlmaLinux上重置密码
Linux

© 2023 进入IT

转到移动版本
欢迎回来!

登录您的帐户

用户名或电子邮件地址
密码

丢失密码?