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

查看:193
本文介绍了如何使用Azure DevOps 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.

请告知.

推荐答案

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

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

要创建新的构建管道,我们可以使用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.

要解决此问题,通常我们将使用REST API

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.

现在,我们为新管道获得了新的请求正文,我们可以将其与REST API Definitions - Create一起使用以创建新管道.

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.

更新:

创建构建定义后,是否会创建 azure-pipelines.yml文件并存储在像Azure Repos这样的存储库中?

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

否,如果您想使用rest api创建 YAML 类型的构建定义,它将不会为我们的仓库创建相应的yaml文件,因为此API Definitions - Create仅发送请求正文到管道无法操作我们的存储库.当前,它支持创建一个构建定义,该定义可以链接到Git存储库中的YAML文件.如果要自动创建Yaml,则可以检查REST API

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.

这应该是需要改进REST API Definitions - Create以支持YAML管道的地方.您可以在我们的UserVoice网站( https://developercommunity.visualstudio.com/content/idea/post.html?space=21 ),这是我们提供产品建议的主要论坛.感谢您帮助我们构建更好的Azure DevOps:

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:

希望这会有所帮助.

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

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