Durch die Nutzung dieser Website, Sie stimmen dem zu Datenschutzrichtlinie.
Akzeptieren
EnterEnterEnter
  • HEIM
  • IT-PROFI
  • Technik
  • MICROSOFT
    • Azurblau
    • Configmgr/sccm
    • DPM
    • Orchestrator
    • Hyper-V
    • Microsoft Edge Insider
    • MSI
    • Büro 365
    • Büro-Insider
    • Power Bi
    • Skype
    • SQL-Server
    • Mannschaften
  • FENSTER
    • Windows Admin Center
    • Windows-Client
    • Windows-Server
  • SCCM-Abfragesammlungsliste
Lektüre: How to Use the Azure DevOps API to Get the Total Build Time (in Minutes) for a Build Agent Pool
Schriftart-ResizerAa
EnterEnter
Schriftart-ResizerAa
  • HEIM
  • IT-PROFI
  • Technik
  • MICROSOFT
  • FENSTER
  • SCCM-Abfragesammlungsliste
Suchen
  • HEIM
  • IT-PROFI
  • Technik
  • MICROSOFT
    • Azurblau
    • Configmgr/sccm
    • DPM
    • Orchestrator
    • Hyper-V
    • Microsoft Edge Insider
    • MSI
    • Büro 365
    • Büro-Insider
    • Power Bi
    • Skype
    • SQL-Server
    • Mannschaften
  • FENSTER
    • Windows Admin Center
    • Windows-Client
    • Windows-Server
  • SCCM-Abfragesammlungsliste
Azure DevOps

How to Use the Azure DevOps API to Get the Total Build Time (in Minutes) for a Build Agent Pool

Veröffentlicht: Februar 18, 2024
5 Min. Lesezeit
AKTIE

How to Use the Azure DevOps API to Get the Total Build Time (in Minutes) for a Build Agent Pool. If you need to roll back from the purchased agent to the free version, this guide will help you.

Azure DevOps is a popular platform for managing software development processes. With its REST API, developers can interact with the platform programmatically and automate tasks such as build and release management. In this tutorial, we will demonstrate how to use the Azure DevOps API to get the total build time (in minutes) for a build agent pool within a specified date range. We will provide step-by-step instructions and use Python to make API requests.

Steps:

  1. Get an Azure DevOps Personal Access Token (PAT) Before we start, we need to obtain an Azure DevOps PAT, which we will use to authenticate our API requests. To create a PAT, go to your Azure DevOps organization settings and click on “Personal access tokens”. Follow the instructions to create a new token with the “Bauen (lesen)” scope.
  2. Set up a Python environment We will be using Python to make our API requests. If you don’t have Python installed, you can download it from the official website (https://www.python.org/downloads/). We also recommend using a virtual environment to manage your Python dependencies. To set up a virtual environment, run the following commands in your terminal:
pip install virtualenv
virtualenv venv
source venv/bin/activate
  1. Install the requests library We will be using the requests library to make our API requests. To install it, run the following command:
pip install requests
  1. Define the API endpoint The API endpoint we will be using is:
https://{username}:{pat}@dev.azure.com/{organization}/{project}/_apis/build/builds?api-version=7.0

Ersetzen {username}, {pat},{organization} Und {project} with your actual organization and project names.

  1. Make the API request To get the total build time for a build agent pool within a specified date range, we need to use the minTime Und maxTime query parameters in our API request. We also need to filter the build results by the build agent pool. Here’s an example Python script that makes the API request and calculates the total build time (in minutes):
pip install python-dateutil requests
import requests
from dateutil.parser import parse

# Set up variables for the API request
organization = "<Organization Name>"
project = "Project Name"
queue_id = "9"
min_time = "2023-04-01"
max_time = "2023-04-05"
# you can leave username as user
username = "user"
pat = "<PAT>"

# Construct the API URL
url = f"https://{username}:{pat}@dev.azure.com/{organization}/{project}/_apis/build/builds?api-version=7.0&minTime={min_time}&maxTime={max_time}&$filter=queue.id eq {queue_id}&$orderby=startTime asc"


# Send the API request
response = requests.get(url)

# Parse the response JSON
json_response = response.json()

# Retrieve the count of build runs
count = json_response["count"]

# Calculate the total build time in seconds
total_build_time = 0
for build in json_response["value"]:
    start_time = parse(build["startTime"])
    finish_time = parse(build["finishTime"])
    duration = finish_time - start_time
    total_build_time += duration.total_seconds()

# Convert the total build time to minutes
total_build_time_minutes = total_build_time / 60

print(f"Number of build runs: {count}")
print(f"Total build time: {total_build_time_minutes:.2f} minutes")

Output example:

Number of build runs: 35
Total build time: 122.19 minutes
GETAGGT:APIAzure DevOpsMicrosoft AzurePython
Vorheriger Artikel Büro-Insider 2212 für Windows
Nächster Artikel Mastering AWS CLI: How to Start EC2 Instances on Ubuntu Like a Pro
Hinterlassen Sie einen Kommentar Hinterlassen Sie einen Kommentar

Hinterlassen Sie eine Antwort Antwort abbrechen

Ihre E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind markiert *

Diese Website verwendet Akismet, um Spam zu reduzieren. Erfahren Sie, wie Ihre Kommentardaten verarbeitet werden.

Übersetzung

English中文(简体)DanskNederlandsFrançaisDeutschItaliano한국어PolskiPortuguêsRomânăEspañolУкраїнська
von Transposh - Übersetzungs-Plug-In für WordPress

Beliebte Beiträge

Systemanforderungen für Windows Server 2016
Windows-Server
Configuration Manager-Abfragesammlungsliste
Configuration Manager-Abfragesammlungsliste
ConfigMgr
Strukturierte/verwaltete Navigation auf modernen Seiten in klassischen Teamsites aktiviert
Techn
SCCM konnte DP-Standorte nicht als erwartete Version von MP abrufen
ConfigMgr

Aktuelle Beiträge

Installieren und Konfigurieren von Fail2ban für den SSH-Schutz unter Ubuntu 24.04
Linux
Aktivieren und Konfigurieren von FirewallD auf AlmaLinux
Linux
Benutzererstellung und SSH-Schlüsseleinrichtung in AlmaLinux
Linux
So setzen Sie das Passwort unter AlmaLinux zurück
Linux

© 2023 Enter

Gehen Sie zur mobilen Version
Willkommen zurück!

Melden Sie sich bei Ihrem Konto an

Benutzername oder E-Mail-Adresse
Passwort

Passwort verloren?