在Azure DevOps中如何使用REST API触发版本? [英] In Azure DevOps How to trigger releases using REST API?

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

问题描述

我在Azure DevOps中具有构建和发布管道.该管道包含三个不同的阶段,即STAGING,QA和PROD.因此,在QA插槽中完成部署后,我想使用REST API触发PROD环境.那么,有可能做同样的事情吗?

I have build and release pipeline in Azure DevOps. That pipeline contains a three different stages namely STAGING, QA and PROD. So, after completion of deployment in QA slot I want to trigger PROD environment using REST API. So, Is that possible to do the same?

推荐答案

不可能在单个发布管道中执行此操作.版本

It is impossible to do this in a single release pipeline. The release create api can only trigger the release pipeline to run, it cannot trigger a certain stage within the pipeline. As the stages in the release pipeline only support after release,after stage and manually.

要满足您的要求,您必须将产品阶段与此发行版(发行版A)分开,这意味着您将使用单阶段产品环境创建新的发行管道(发行版B).

To achieve your requirements, You will have to separate your prod stage from this release(Release A), which means you will create a new release pipeline(Release B) with the a single stage prod environment.

然后,您可以在QA阶段结束时在发布管道A中添加powershell任务,以调用API触发版本B部署到Prod环境.下面的脚本例如:

Then you can add a powershell task at the end of QA stage in release pipeline A to call the API to trigger Release B to deploy to Prod environment. below script is for example:

$releaseUrl ="https://vsrm.dev.azure.com/<organization>/<project>/_apis/release/releases?api-version=5.1"

$body = '{
  "definitionId": 4, # release definition id
  "description": "Creating prod release",
  "artifacts": [
    {
      "alias": "_NunitProject", #artifacts alias
      "instanceReference": {
        "id": "1367", #build id related to the artifacts
        "name": null
      }
    }
  ],
  "isDraft": false,
  "reason": "none",
  "manualEnvironments": null,
  }'


$result4 = Invoke-RestMethod -Uri $releaseUrl -Headers @{ Authorization = "Bearer $env:SYSTEM_ACCESSTOKEN" } -Method post -Body $body -ContentType "application/json"

这篇关于在Azure DevOps中如何使用REST API触发版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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