如何使用 Azure DevOps REST API 创建新的构建管道? [英] How to create new build pipeline using Azure DevOps REST API?

查看:48
本文介绍了如何使用 Azure DevOps REST API 创建新的构建管道?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试以编程方式创建新的构建管道.我正在为此操作寻找 Azure DevOps REST API.我没有得到使用 REST API 创建管道的正确示例.

请指教.

解决方案

如何使用 Azure DevOps REST API 创建新的构建管道?

要创建新的构建管道,我们可以使用 REST API

希望这会有所帮助.

I'm trying to create new build pipeline through programmatically. I'm looking for Azure DevOps REST API for this action. I didn't get the proper examples for creating the pipeline using REST API.

Please advise.

解决方案

How to create new build pipeline using Azure DevOps REST API?

To create the new build pipeline, we could use the REST API Definitions - Create:

POST https://dev.azure.com/{organization}/{project}/_apis/build/definitions?api-version=5.0

But we need provide too much information in the Request Body, this will be a big project and error-prone. That also the reason why the document not provide a sample Request Body there.

To resolve this issue, usually we would use the REST API Definitions - Get to get the Response Body from the template pipeline:

GET https://dev.azure.com/{organization}/{project}/_apis/build/definitions/{definitionId}?api-version=5.0

Then we just need to update the corresponding properties by modifying the Response Body.

Now, we get the new Request Body for the new pipeline, we could use it with REST API Definitions - Create to create a new pipeline.

You could check this thread for some more details.

Update:

After creating the build definition, Will it create azure-pipelines.yml file and store in the repository like Azure Repos?

No, if you want to create a YAML type build definition using the rest api, it will not create the corresponding yaml file to our repo, because this API Definitions - Create only send the request body to the pipeline does not operate our repo. Currently, it support creating a build definition that links to a YAML file within the Git repo. If you want to create the yaml automatically, you could check the REST API Pushes - Create.

This should be where the REST API Definitions - Create needs to be improved to support the YAML pipeline. You could add your request for this feature on our UserVoice site (https://developercommunity.visualstudio.com/content/idea/post.html?space=21 ), which is our main forum for product suggestions. Thank you for helping us build a better Azure DevOps:

Hope this helps.

这篇关于如何使用 Azure DevOps REST API 创建新的构建管道?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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