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

如何检索Azure Data Factory中关联Azure DevOps特定分支的管道列表

检索与Azure DevOps特定分支关联的ADF管道列表

正确方法说明

你需要获取的是Azure DevOps仓库分支中存储的ADF管道源代码定义文件,而非ADF实时环境中的已发布管道。以下是两种可行方案:

方案1:使用Azure DevOps REST API(PowerShell)

通过API递归获取指定分支下ADF管道目录的所有JSON文件(ADF管道以JSON格式存储):

# 配置参数
$org = "你的组织名称"
$project = "你的项目名称"
$repoId = "目标仓库ID"
$targetBranch = "要检索的分支名(如main)"
$adfPipelinesPath = "/ADF/pipelines"

# 构建API请求URL
$apiUrl = "https://dev.azure.com/$org/$project/_apis/git/repositories/$repoId/items?path=$adfPipelinesPath&recursionLevel=Full&versionDescriptor.version=$targetBranch&versionDescriptor.versionType=Branch&api-version=7.1-preview.1"

# 配置认证(使用PAT令牌)
$patToken = "你的Azure DevOps PAT令牌(需包含代码读取权限)"
$authHeader = @{Authorization = "Basic " + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(":$patToken"))}

# 发起请求并处理结果
$response = Invoke-RestMethod -Uri $apiUrl -Headers $authHeader -Method Get
$adfPipelineFiles = $response.value | Where-Object { !$_.isFolder -and $_.name -match "\.json$" }

# 输出管道列表
$adfPipelineFiles | ForEach-Object {
    [PSCustomObject]@{
        管道名称 = $_.name -replace "\.json$", ""
        文件路径 = $_.path
        最后提交ID = $_.commitId
    }
}

方案2:使用Azure CLI(带DevOps扩展)

  1. 先安装azure-devops扩展:
az extension add --name azure-devops
  1. 登录并获取管道文件列表:
# 登录Azure DevOps
az devops login

# 列出指定分支下的ADF管道文件
az repos item list --org https://dev.azure.com/你的组织名 --project 你的项目名 --repository 仓库名 --path "/ADF/pipelines" --branch 目标分支名 --recursive --output json | jq '.[] | select(.isFolder == false and .path | test("\\.json$")) | {管道名称: .name | rtrimstr(".json"), 文件路径: .path}'

关键注意点

  • ADF与Git集成时,管道默认存储在/ADF/pipelines路径下,若你的路径不同,需调整对应参数
  • Get-AzDataFactoryV2Pipeline仅返回ADF服务中已发布的管道,与Git仓库中的源代码定义是两个不同的概念
  • 确保使用的PAT令牌拥有代码读取权限,否则会访问被拒绝

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.19 01:15:09