用于运行构建或管道的 Azure REST API [英] Azure REST API for running builds or pipelines
问题描述
我正在尝试使用其 REST api 为特定分支自动创建 Azure Pipelines.
I am trying to automate the creation of Azure Pipelines for a particular branch using their REST api.
但是,我很难使用他们几乎所有的 API,因为他们的文档缺少示例.
However, I am struggling to use almost all their API's, as their documentation lacks examples.
List 和 Get 之类的东西很简单.
Things like List and Get are simple enough.
但是,当涉及到排队构建时:https://docs.microsoft.com/en-us/rest/api/azure/devops/build/builds/queue?view=azure-devops-rest-6.0
However, when it comes to queuing a build: https://docs.microsoft.com/en-us/rest/api/azure/devops/build/builds/queue?view=azure-devops-rest-6.0
POST https://dev.azure.com/{organization}/{project}/_apis/build/builds?api-version=6.0
{
"parameters": <parameters>, // how do i send paramters
"definition": {
"id": 1
},
"sourceBranch": "refs/heads/feature/my-pipeline",
"sourceVersion": "d265f01aeb4e677a25725f44f20ceb3ff1d7d767"
}
我目前正在努力发送参数.我试过了:
I am currently struggling to send parameters. I have tried:
简单的 JSON,如:
Simple JSON like:
"parameters": {
"appId": "bab",
"platform": "android",
"isDemo": true
}
和字符串化 JSON 版本,如:
and stringify version of JSON like:
"parameters": "{"appId": "bab","platform": "android","isDemo": true}"
但似乎都不起作用.
它一直给我错误:
{
"$id": "1",
"customProperties": {
"ValidationResults": [
{
"result": "error",
"message": "A value for the 'appId' parameter must be provided."
},
{
"result": "error",
"message": "A value for the 'platform' parameter must be provided."
},
{
"result": "error",
"message": "A value for the 'isDemo' parameter must be provided."
}
]
},
"innerException": null,
"message": "Could not queue the build because there were validation errors or warnings.",
"typeName": "Microsoft.TeamFoundation.Build.WebApi.BuildRequestValidationFailedException, Microsoft.TeamFoundation.Build2.WebApi",
"typeKey": "BuildRequestValidationFailedException",
"errorCode": 0,
"eventId": 3000
}
文档对如何发送此数据非常不清楚:https://docs.microsoft.com/en-us/rest/api/azure/devops/build/builds/queue?view=azure-devops-rest-6.1#propertiescollection
The docs is very unclear in how to send this data: https://docs.microsoft.com/en-us/rest/api/azure/devops/build/builds/queue?view=azure-devops-rest-6.1#propertiescollection
非常感谢您的帮助.
推荐答案
我相信您无法通过队列 API 传递运行时参数.而是使用 运行 API
I believe you cannot pass runtime parameters trough the Queue API. Instead, use Runs API
这样,您的请求正文(使用 Content-type: application/json
)应该类似于以下内容:
With that, your request body (use Content-type: application/json
) should look something similar to this:
{
"resources": {
"repositories": {
"self": {
"refName": "refs/heads/feature/my-pipeline"
}
}
},
"templateParameters": {
"appId": "bab"
"platform": "android"
"isDemo": true
}
}
这篇关于用于运行构建或管道的 Azure REST API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!