用于运行内部版本或管道的Azure REST API [英] Azure REST API for running builds or pipelines

查看:89
本文介绍了用于运行内部版本或管道的Azure REST API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用其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/zh-cn/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/zh-cn/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

非常感谢您的帮助.

推荐答案

我相信您无法通过Queue API传递运行时参数.而是使用运行API

I believe you cannot pass runtime parameters trough the Queue API. Instead, use Runs API

这样,您的请求主体应类似于以下内容:

With that, your request body 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆