You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过Azure DevOps API获取特定仓库对应的发布信息,并识别发布管道关联的仓库以实现审批自动化?

Hey Stephanie, let's break down your Azure DevOps API questions step by step—this kind of automation for release approvals is super common, so I’ve got actionable steps for you.

1. How to Get Azure DevOps Release Info for a Specific Repository

To map a repo to its related releases, you’ll need to chain a few API calls (since releases are tied to build pipelines, which are tied to repos):

  • Step 1: Grab your target repo’s ID
    First, fetch all repos in your project and filter for the one you care about. Use this API endpoint:

    GET https://dev.azure.com/{organization}/{project}/_apis/git/repositories?api-version=7.1-preview.1
    

    Look for the id field in the response object matching your repo name—you’ll need this for the next step.

  • Step 2: Find build pipelines (definitions) linked to the repo
    Next, pull all build definitions in your project and filter those that reference your target repo. Use:

    GET https://dev.azure.com/{organization}/{project}/_apis/build/definitions?api-version=7.1-preview.7
    

    Each build definition has a repository object with an id field. Filter the results to only keep definitions where repository.id matches your repo’s ID from Step 1. Save these build definition IDs—they’re your link to releases.

  • Step 3: Fetch releases tied to those build pipelines
    Finally, get all releases and filter for ones triggered by your target build definitions. Use:

    GET https://dev.azure.com/{organization}/{project}/_apis/release/releases?api-version=7.1-preview.8
    

    Check the artifacts array in each release object. Look for definitionReference.definition.id—this matches the build definition ID from Step 2. Any release with a matching ID is tied to your target repo.

    Pro tip: To avoid filtering locally, you can pass multiple build definition IDs directly in the API call with definitionId=123,456 (replace with your IDs) to narrow results upfront.

2. API to Get Repository Info Linked to a Pipeline

Great news—you didn’t miss a hidden API! The build definition API itself includes all repository details for a pipeline.

To get the repo linked to a specific build pipeline, call:

GET https://dev.azure.com/{organization}/{project}/_apis/build/definitions/{definitionId}?api-version=7.1-preview.7

In the response, look for the repository object—this includes:

  • id: The repo’s unique ID
  • name: The repo’s display name
  • url: The repo’s API endpoint
  • type: The repo type (e.g., Git)

For YAML pipelines, you might also see a yamlRepository field with additional context, but the repository field is the primary source for repo association regardless of pipeline type.

A quick shortcut: If you want to find all pipelines linked to a specific repo in one go, use the build definition API with a filter:

GET https://dev.azure.com/{organization}/{project}/_apis/build/definitions?$filter=repository/id eq '{repoId}'&api-version=7.1-preview.7

This returns only build definitions tied to your target repo, no manual filtering needed.

Don’t forget: All these API calls require a Personal Access Token (PAT) with at least Build (Read) and Release (Read) permissions to work.

内容的提问来源于stack exchange,提问作者Stephanie

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.29 14:02:32