首页 > 解决方案 > Azure DevOps API 发布定义错误

问题描述

我正在使用 API 创建 azure-devops 发布管道,但出现错误。我也验证了 json 并且来自https://jsonlint.com/的任何帮助都是正确的

Azure DevOps API 版本定义

错误:"message": "VS402982: A retention policy is not set for the stage ‘Test-New-2’. Retention policies at the release pipeline level are deprecated. Use a retention policy at the stage level

POST https://vsrm.dev.azure.com/{{organization}}/{{project}}/_apis/release/definitions?api-version=6.0

json正文:

"retentionPolicy": {
                "daysToKeep": 30,
                "releasesToKeep": 3,
                "retainBuild": true
            },

标签: apiazure-devops

解决方案


是的,应该是语法问题,要创建发布定义,可以参考这个示例

重新请求网址:

POST https://vsrm.dev.azure.com/{organization}/{project}/_apis/release/definitions?api-version=6.0

请求正文:

{
  "source": "undefined",
  "revision": 1,
  "description": null,
  "createdBy": null,
  "createdOn": "0001-01-01T00:00:00",
  "modifiedBy": null,
  "modifiedOn": "0001-01-01T00:00:00",
  "isDeleted": false,
  "variables": {},
  "variableGroups": [],
  "environments": [
    {
      "id": 0,
      "name": "PROD",
      "variables": {},
      "variableGroups": [],
      "preDeployApprovals": {
        "approvals": [
          {
            "rank": 1,
            "isAutomated": false,
            "isNotificationOn": false,
            "approver": {
              "displayName": null,
              "id": "aeb95c63-4fac-4948-84ce-711b0a9dda97"
            },
            "id": 0
          }
        ]
      },
      "postDeployApprovals": {
        "approvals": [
          {
            "rank": 1,
            "isAutomated": true,
            "isNotificationOn": false,
            "id": 0
          }
        ]
      },
      "deployPhases": [
        {
          "deploymentInput": {
            "parallelExecution": {
              "parallelExecutionType": "none"
            },
            "skipArtifactsDownload": false,
            "artifactsDownloadInput": {},
            "queueId": 15,
            "demands": [],
            "enableAccessToken": false,
            "timeoutInMinutes": 0,
            "jobCancelTimeoutInMinutes": 1,
            "condition": "succeeded()",
            "overrideInputs": {}
          },
          "rank": 1,
          "phaseType": "agentBasedDeployment",
          "name": "Run on agent",
          "workflowTasks": []
        }
      ],
      "environmentOptions": {
        "emailNotificationType": "OnlyOnFailure",
        "emailRecipients": "release.environment.owner;release.creator",
        "skipArtifactsDownload": false,
        "timeoutInMinutes": 0,
        "enableAccessToken": false,
        "publishDeploymentStatus": false,
        "badgeEnabled": false,
        "autoLinkWorkItems": false,
        "pullRequestDeploymentEnabled": false
      },
      "demands": [],
      "conditions": [],
      "executionPolicy": {
        "concurrencyCount": 0,
        "queueDepthCount": 0
      },
      "schedules": [],
      "retentionPolicy": {
        "daysToKeep": 30,
        "releasesToKeep": 3,
        "retainBuild": true
      },
      "properties": {},
      "preDeploymentGates": {
        "id": 0,
        "gatesOptions": null,
        "gates": []
      },
      "postDeploymentGates": {
        "id": 0,
        "gatesOptions": null,
        "gates": []
      },
      "environmentTriggers": []
    }
  ],
  "artifacts": [],
  "triggers": [],
  "releaseNameFormat": null,
  "tags": [],
  "properties": {},
  "id": 0,
  "name": "Fabrikam-web",
  "projectReference": null,
  "_links": {}
}

我在我这边测试它,它对我有用。

在此处输入图像描述


推荐阅读