我有以下脚本
Param(
[string]$vstsAccount = "abc,
[string]$projectName = "abc",
[string]$user = "",
[string]$token = "xyz"
)
# Base64-encodes the Personal Access Token (PAT) appropriately
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $user,$token)))
$verb = "POST"
$body = @"
{
"definition": {
"id": 20
}
}
"@
$uri = "https://$($vstsAccount).visualstudio.com/DefaultCollection/$($projectName)/_apis/build/builds?api-version=4.1"
$result = Invoke-RestMethod -Uri $uri -Method $verb -ContentType "application/json" -Body (ConvertTo-Json $body) -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)}
Run Code Online (Sandbox Code Playgroud)
但是我得到这个错误
Invoke-RestMethod : {"$id":"1","innerException":null,"message":"This request expects an object in the request body, but the supplied data could not …Run Code Online (Sandbox Code Playgroud) 我想通过API调用自动化Azure管道的排队,获取有关管道/构建/作业状态的信息,
Azure Pipelines文档仅针对“调用HTTP Rest API”任务提及“ API”:https : //docs.microsoft.com/zh-cn/azure/devops/pipelines/tasks/utility/http-rest-api?view= vsts这可能会派上用场,但不是我想要的。
有一个“ Azure DevOps Services REST API”:https ://docs.microsoft.com/zh-cn/rest/api/azure/devops/?view=azure-devops-rest-5.1 但我找不到任何提到“管道”,所以这似乎也不是对的。
StackOverflow标记azure-devops-rest-api也仅提及VSTS和TFS:
Visual Studio Team Services REST API是一组API,允许管理Visual Studio Team Services帐户以及TFS 2015和2017服务器。
除了这两个结果,我只找到这些版本的其他副本或其他版本的翻译-以及许多与Azure无关的文档。
我只是使用错误的单词进行搜索吗?
是否有适用于Azure DevOps管道的实际API?
它有可用的API资源管理器吗?
它是否具有适用于JavaScript,Ruby或PHP等语言的客户端?
我正在尝试使用其 REST api 为特定分支自动创建 Azure Pipelines。
但是,我很难使用他们几乎所有的 API,因为他们的文档缺少示例。
List 和 Get 之类的东西很简单。
但是,在排队构建时: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"
}
Run Code Online (Sandbox Code Playgroud)
我目前正在努力发送参数。我试过了:
简单的 JSON,如:
"parameters": {
"appId": "bab",
"platform": "android",
"isDemo": true
}
Run Code Online (Sandbox Code Playgroud)
和字符串化 JSON 版本,如:
"parameters": "{\"appId\": \"bab\",\"platform\": \"android\",\"isDemo\": true}"
Run Code Online (Sandbox Code Playgroud)
但似乎没有一个工作。
它不断给我错误:
{
"$id": "1",
"customProperties": {
"ValidationResults": [
{
"result": "error",
"message": "A value for the 'appId' parameter must be …Run Code Online (Sandbox Code Playgroud)