尝试使用 Azure DevOps Rest 创建发布管道时出错 API

Error when trying to create a release pipeline using the Azure DevOps Rest API

我正在尝试使用 Azure Devops 创建发布管道 API,但我收到了以下错误:

{
    "$id": "1",
    "innerException": null,
    "message": "VS402936: Release pipeline with ID 467 does not exist. Specify a valid ID and try again.",
    "typeName": "Microsoft.VisualStudio.Services.ReleaseManagement.WebApi.Exceptions.ReleaseDefinitionNotFoundException, Microsoft.VisualStudio.Services.ReleaseManagement.WebApi",
    "typeKey": "ReleaseDefinitionNotFoundException",
    "errorCode": 0,
    "eventId": 3000
}

我的印象是向 https://vsrm.dev.azure.com/{organization}/{project}/_apis/release/definitions?api-version=6.0 发送 POST 请求实际上会创建发布管道 - 我误解了吗?

我对此的理解来自这个问题:https://developercommunity.visualstudio.com/t/api-documentation-out-of-date/1437337 这确实帮助我创建了构建管道

请在下面找到请求正文 - 请注意,由于我删除了个人和组织信息,因此某些值会有所不同:

{
  "id": 467,
  "name": "testProject",
  "source": "restApi",
  "revision": 1,
  "description": "Built by project_setup.py",
  "createdBy": null,
  "createdOn": "2021-11-23T10:55:39.418Z",
  "modifiedBy": null,
  "modifiedOn": "2021-11-23T10:55:39.418Z",
  "isDeleted": false,
  "variables": {},
  "variableGroups": [],
  "environments": [
    {
      "id": 628,
      "name": "dev",
      "retentionPolicy": {
        "daysToKeep": 30,
        "releasesToKeep": 3,
        "retainBuild": true
      },
      "preDeployApprovals": {
        "approvals": [
          {
            "rank": 1,
            "isAutomated": false,
            "isNotificationOn": false,
            "approver": {
              "displayName": null,
              "id": "aeb95c63-4fac-4948-84ce-711b0a9dda97"
            },
            "id": 628
          }
        ]
      },
      "postDeployApprovals": {
        "approvals": [
          {
            "rank": 1,
            "isAutomated": true,
            "isNotificationOn": false,
            "id": 628
          }
        ]
      },
      "deployPhases": [
        {
          "deploymentInput": {
            "parallelExecution": {
              "parallelExecutionType": "none"
            },
            "skipArtifactsDownload": false,
            "artifactsDownloadInput": {},
            "queueId": 154,
            "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": [],
      "properties": {},
      "preDeploymentGates": {
        "id": 628,
        "gatesOptions": null,
        "gates": []
      },
      "postDeploymentGates": {
        "id": 628,
        "gatesOptions": null,
        "gates": []
      },
      "environmentTriggers": [],
      "rank": 1,
      "owner": {
        "displayName": "<myemail>",
        "url": "https://dev.azure.com/<mycompany>/_apis_Identities/<myid>",
        "_links": {
          "avatar": {
            "href": "https://dev.azure.com/w2globaldata/_apis/GraphProfile/MemberAvatars/<mydescriptor>"
          }
        },
        "id": "<myid>",
        "uniqueName": "<myemail>",
        "imageUrl": "https://dev.azure.com/<company>/_api/_common/identityImage?id=<myid>",
        "descriptor": "<mydescriptor>"
      }
    }
  ],
  "artifacts": [],
  "triggers": [],
  "releaseNameFormat": null,
  "tags": [],
  "properties": {},
  "projectReference": null,
  "_links": {}
}

如果有人可以提供任何帮助,或者有任何这方面的经验,我们将不胜感激!

这取决于您要创建的内容....在您的情况下,您似乎想要更新您在正文中定义的 ID 为 467 的现有发布定义:

{ "id": 467, }

如果要创建发布定义,则必须使用此示例:Create release definition。所以尝试删除ID 属性.

如果要创建现有版本定义的新版本,请使用此示例:Sample Request