Ao usar este site, você concorda com o política de Privacidade.
Aceitar
Entrar em TIEntrar em TIEntrar em TI
  • LAR
  • PROFISSIONAL DE TI
  • TECNOLOGIA
  • Microsoft
    • Azul
    • ConfigMgr/SCCM
    • PMD
    • Orquestrador
    • Hiper-V
    • Microsoft Edge Insider
    • MSI
    • Escritório 365
    • Office Insider
    • Power BI
    • Skype
    • Servidor SQL
    • Equipes
  • WINDOWS
    • Centro de Administração do Windows
    • Cliente Windows
    • Servidor Windows
  • Lista de coleta de consultas SCCM
Leitura: Creating a New Azure DevOps Build and Updating its Variables with REST API
Redimensionador de fontesAh
Entrar em TIEntrar em TI
Redimensionador de fontesAh
  • LAR
  • PROFISSIONAL DE TI
  • TECNOLOGIA
  • Microsoft
  • WINDOWS
  • Lista de coleta de consultas SCCM
Procurar
  • LAR
  • PROFISSIONAL DE TI
  • TECNOLOGIA
  • Microsoft
    • Azul
    • ConfigMgr/SCCM
    • PMD
    • Orquestrador
    • Hiper-V
    • Microsoft Edge Insider
    • MSI
    • Escritório 365
    • Office Insider
    • Power BI
    • Skype
    • Servidor SQL
    • Equipes
  • WINDOWS
    • Centro de Administração do Windows
    • Cliente Windows
    • Servidor Windows
  • Lista de coleta de consultas SCCM
Azure DevOps

Creating a New Azure DevOps Build and Updating its Variables with REST API

Publicado em novembro 29, 2024
4 Leitura mínima
COMPARTILHAR

Creating a New Azure DevOps Build and Updating its Variables with 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.

Neste artigo, 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:

  • O -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. O api-version parameter specifies the version of the API we want to use.
  • O -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. O id property specifies the ID of the build definition.
    • parameters: a JSON-formatted string that specifies the build parameters. O {parameter_name} e {parameter_value} placeholders should be replaced with the actual parameter name and value, respectively.

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:

  • O -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
MARCADO:APIAzure DevOpsBashCI/CDcurlJSONMicrosoft Azure
Artigo Anterior Smoothly Upgrading from Ubuntu 18 to Ubuntu 20
Próximo artigo Activating EPEL and EPEL Next in Almalinux 9 or Rocky Linux 9 Activating EPEL and EPEL Next in Almalinux 9 or Rocky Linux 9
Deixe um comentário Deixe um comentário

Deixe uma resposta Cancelar resposta

Seu endereço de e-mail não será publicado. Os campos obrigatórios estão marcados *

Este site usa Akismet para reduzir spam. Saiba como os dados dos seus comentários são processados.

Tradução

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

Postagens populares

Requisitos do sistema para Windows Server 2016
Servidor Windows
Lista de coleta de consultas do Configuration Manager
Lista de coleta de consultas do Configuration Manager
ConfigMgr
Navegação estruturada/gerenciada habilitada em páginas modernas em sites de equipe clássicos
Tecnologia
SCCM Falha ao obter locais de DP como a versão esperada do MP
ConfigMgr

Postagens recentes

Instalando e configurando Fail2ban para proteção SSH no Ubuntu 24.04
Linux
Habilitando e configurando FirewallD no AlmaLinux
Linux
Criação de usuário e configuração de chave SSH no AlmaLinux
Linux
Como redefinir a senha no AlmaLinux
Linux

© 2023 Entrar em TI

Vá para a versão móvel
banner
Bem vindo de volta!

Faça login na sua conta

Nome de usuário ou endereço de e-mail
Senha

Perdeu sua senha?