有一个 restful api 允许您为提交页面中的提交创建一个git 提交状态。
您可以在 Jenkins 中调用以下 API 作为构建后操作。
POST https://dev.azure.com/{organization}/{project}/_apis/git/repositories/{repositoryId}/commits/{commitId}/statuses?api-version=5.1
commitId 是提交 SHA。您可以从Project Settings中Repos下的Repositories获取 repositoryId 。它在网址中。检查下面的屏幕截图。
下面是在 powershell 脚本中创建提交状态的示例。
$url="https://dev.azure.com/Org/Proj/_apis/git/repositories/....-..-442d-9dbe-76debfba1c60/commits/....faac7aafeefb3f1b83c/statuses?api-version=5.1"
$connectionToken ="Person Access Token"
$base64AuthInfo= [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($connectionToken)"))
$body ='{
"state": "succeeded",
"description": "The build is successful",
"targetUrl": "https://dev.azure.com/.../.../_build/results?buildId=1577",
"context": {
"name": "Build123",
"genre": "continuous-integration"
}}'
Invoke-RestMethod -Uri $url -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)} -Method Post -ContentType "application/json" -Body $body