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

求调用Azure DevOps API获取Git仓库最新变更集描述的PowerShell脚本

获取Azure DevOps Git仓库最新变更集描述的PowerShell脚本

以下是直接可用的PowerShell脚本,调用Azure DevOps REST API获取指定Git仓库的最新变更集(提交)描述:

# 配置参数
$organizationName = "你的组织名"
$projectName = "你的项目名"
$repositoryName = "你的Git仓库名"
$patToken = "你的个人访问令牌(PAT)"

# 构建API请求URL
$apiUrl = "https://dev.azure.com/$organizationName/$projectName/_apis/git/repositories/$repositoryName/commits?top=1&api-version=7.1-preview.1"

# 转换PAT为Base64编码的认证头
$authHeader = @{Authorization = 'Basic ' + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(":$patToken"))}

# 发送API请求
try {
    $response = Invoke-RestMethod -Uri $apiUrl -Headers $authHeader -Method Get -ContentType "application/json"
    # 提取最新变更集的描述信息
    $latestCommitMessage = $response.value[0].comment
    Write-Host "最新变更集描述:`n$latestCommitMessage"
}
catch {
    Write-Error "请求失败:$_"
}

使用说明

  • 个人访问令牌(PAT):需要在Azure DevOps中生成,权限至少勾选"代码(读取)"
  • 参数替换:将脚本中的你的组织名、你的项目名、你的Git仓库名、你的个人访问令牌(PAT)替换为实际值
  • API版本:脚本使用的是7.1-preview.1,如果需要可以替换为最新的稳定版API版本

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.24 07:45:39