azure-devops - 如何在 Devops/VSTS 中自动启动以前成功的发布

标签 azure-devops azure-pipelines devops azure-devops-extensions devops-services

如果当前版本失败,如何自动运行之前成功的版本?

enter image description here

例如:如果 A(Current release) 失败则自动触发 B(Previous success release) release。从另一个发布定义触发。

最佳答案

用powershell调用api不用那么复杂。我们有内置功能可以满足您的要求。由于发布流水线由一个或多个阶段组成,重新部署发布流水线可视为重新运行阶段。

所以先打开发布管道定义。然后导航到阶段的部署后条件 => 启用自动重新部署触发器 => 选择事件操作:

enter image description here

查看实际执行结果:

enter image description here

这是 Azure Devops 的优势,因此如果在 Prod 部署期间出现问题,您无需担心,因为该工具会自动撤消上次成功的部署。

更新:

$connectionToken="{PAT}" 

$url="https://vsrm.dev.azure.com/{org}/{project}/_apis/release/releases?api-version=6.0"

$token = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($connectionToken)"))
    
$Body=@"
{
  "definitionId": {specific release definition id},
  "description": "Creating release from powershell",
  "artifacts": [
    {
      "alias": "{artifact name}",
      "instanceReference": {
        "id": "{buildid}",
        "name": null
      }
    }
  ],
  "isDraft": false,
  "reason": "none",
  "manualEnvironments": null
}
"@
Invoke-RestMethod -Uri $url -Headers @{Authorization = "Basic $token"} -Method Post -Body $Body -ContentType application/json

关于azure-devops - 如何在 Devops/VSTS 中自动启动以前成功的发布,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64043553/

相关文章:

linux - 在 Docker 容器中更新 apk 期间出现错误的文件描述符错误......为什么?

asp.net-mvc - 构建面向完整 .net 框架的 VS2017 .net core 应用程序

azure-devops - 如何将 Mark Down 样式添加到 Azure DevOps 网站

c# - Azure DevOps Build 缺少程序集引用

azure-devops - 以前的 Azure Pipeline 构建中的预定义变量

ruby - Chef : Can a variable set within one ruby_block be used later in a recipe?

azure-devops - 使用 azure devops 部署到离线服务器

git - 如何在 VSTS Rest API 中获取提交的分支名称?

json - 将 JSON 变量传递给 AzureDevops Release 定义

linux - Bash 在 CSV 列中选择多个值