이 사이트를 이용함으로써, 당신은 다음에 동의합니다 개인 정보 보호 정책.
수용하다
엔터인IT엔터인IT엔터인IT
  • 집
  • IT 프로
  • 기술
  • 마이크로소프트
    • 하늘빛
    • 구성 관리자/SCCM
    • DPM
    • 오케스트레이터
    • 하이퍼-V
    • 마이크로소프트 엣지 인사이더
    • MSI
    • 사무실 365
    • 사무실 내부자
    • 파워 BI
    • 스카이프
    • SQL 서버
    • 팀
  • 윈도우
    • Windows 관리 센터
    • 윈도우 클라이언트
    • 윈도우 서버
  • SCCM 쿼리 컬렉션 목록
독서: How to Use the Azure DevOps API to Get the Total Build Time (in Minutes) for a Build Agent Pool
글꼴 크기 조정기아아
엔터인IT엔터인IT
글꼴 크기 조정기아아
  • 집
  • IT 프로
  • 기술
  • 마이크로소프트
  • 윈도우
  • SCCM 쿼리 컬렉션 목록
찾다
  • 집
  • IT 프로
  • 기술
  • 마이크로소프트
    • 하늘빛
    • 구성 관리자/SCCM
    • DPM
    • 오케스트레이터
    • 하이퍼-V
    • 마이크로소프트 엣지 인사이더
    • MSI
    • 사무실 365
    • 사무실 내부자
    • 파워 BI
    • 스카이프
    • SQL 서버
    • 팀
  • 윈도우
    • Windows 관리 센터
    • 윈도우 클라이언트
    • 윈도우 서버
  • SCCM 쿼리 컬렉션 목록
Azure DevOps

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

Published August 26, 2024
5 최소 읽기
공유하다

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.

단계:

  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 “Build (read)” 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

Replace {username}, {pat},{organization} 그리고 {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 그리고 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
태그됨:APIAzure DevOpsMicrosoft AzurePython
이전 기사 사무실 내부자 2212 Windows의 경우
다음 기사 Mastering AWS CLI: How to Start EC2 Instances on Ubuntu Like a Pro
코멘트를 남겨주세요 코멘트를 남겨주세요

답장을 남겨주세요 답장 취소

귀하의 이메일 주소는 공개되지 않습니다. 필수 입력란이 표시되어 있습니다 *

이 사이트는 스팸을 줄이기 위해 Akismet을 사용합니다.. 댓글 데이터가 처리되는 방법 알아보기.

번역

English中文(简体)DanskNederlandsFrançaisDeutschItaliano한국어PolskiPortuguêsRomânăEspañolУкраїнська
 번역 편집
~에 의해 Transposh - translation plugin for wordpress

인기 게시물

Windows Server의 시스템 요구 사항 2016
윈도우 서버
구성 관리자 쿼리 컬렉션 목록
구성 관리자 쿼리 컬렉션 목록
구성 관리자
클래식 팀 사이트의 최신 페이지에서 구조적/관리형 탐색 활성화
기술
SCCM이 DP 위치를 MP에서 예상 버전으로 가져오지 못했습니다.
구성 관리자

최근 게시물

Ubuntu에서 SSH 보호를 위한 Fail2ban 설치 및 구성 24.04
리눅스
AlmaLinux에서 FirewallD 활성화 및 구성
리눅스
AlmaLinux에서 사용자 생성 및 SSH 키 설정
리눅스
AlmaLinux에서 비밀번호를 재설정하는 방법
리눅스

© 2023 엔터인IT

모바일 버전으로 이동하십시오
광고배너
돌아온 것을 환영합니다!

귀하의 계정에 로그인하세요

사용자 이름 또는 이메일 주소
비밀번호

비밀번호를 잃어버렸습니다?