如何扩展返回的发布定义中的所有属性

How to expand all properties in returned release definition

我们的 Azure DevOps 架构使用单一发布管道来升级和启动其他管道。在踢出的管道 运行 发布之前,"kicker" 管道更新 "kickee" 管道的发布定义。我只有 "kickee" 管道的名称,没有 ID,因此要升级管道,我们调用 API 记录在:

https://docs.microsoft.com/en-us/rest/api/azure/devops/release/Definitions/List?view=azure-devops-rest-5.0#releasedefinitionexpands

因为我们需要修改发布定义的几个方面,所以我需要使用 $expand 参数来扩展一些将要更新的属性(变量、工件、环境等)。文档似乎表明可以扩展多个属性,但不清楚如何执行此操作。这是传递给参数的一些列表吗?如果是,是什么将每个列表分开?是否期望多次指定该参数(根据 How to pass multiple parameters in a querystring 我猜这是合法的)?其他选项?

我解决了这个问题,方法是使用列表 API 获取定义 ID,然后调用获取 API 获取特定版本定义的全部内容。如果我需要一次更新大量发布定义,这并不理想,但可以满足我的需要,因为我一次只需要更新一个定义。

您用 , 分隔属性。

例如:

https://vsrm.dev.azure.com/{your-account}/{your-project}/_apis/release/definitions?$expand=Environments,Artifacts&api-version=5.0-preview.3

您将在结果中得到 EnvironmentsArtifacts:

         "environments": [
            {
               "id": 1,
               "name": "Environment 1",
               "rank": 1,
               "owner": {
                  "displayName": "Shayki Abramczyk",
                  "url": "https://app.vssps.visualstudio.com/xxxxxxx-7cea-4070-bdad-0e1f6e0bc9e7/_apis/Identities/7a9a9b44-a2f1-6dfd-a7f6-e49cafde66b0",
                  "_links": {
                     "avatar": {
                        "href": "https://dev.azure.com/shaykia/_apis/GraphProfile/MemberAvatars/msa.xxxYTliNDQtYTJmMS03ZGZkLWE3ZjYtZTQ5Y2FmZGU2NmIw"
                     }
                  },
                  "id": "xxxxx-a2f1-6dfd-a7f6-e49cafde66b0",
                  "uniqueName": "xxxxx@gmail.com",
                  "imageUrl": "https://dev.azure.com/shaykia/_api/_common/identityImage?id=xxxxx-a2f1-6dfd-a7f6-e49cafde66b0",
                  "descriptor": "msa.N2E5YTliNDQtYTJmMS03ZGZkLWE3ZjYtZTQ5Y2FmZGU2NmIw"
               },
               "variableGroups": [],
               "schedules": [],
               "currentRelease": {
                  "id": 7,
                  "url": "https://vsrm.dev.azure.com/shaykia/xxxxx-b891-4fe5-b2fe-9b9a19a1d1af/_apis/Release/releases/7",
                  "_links": {}
               },
               "retentionPolicy": {
                  "daysToKeep": 30,
                  "releasesToKeep": 3,
                  "retainBuild": true
               },
               "properties": {},
               "preDeploymentGates": {
                  "id": 0,
                  "gatesOptions": null,
                  "gates": []
               },
               "postDeploymentGates": {
                  "id": 0,
                  "gatesOptions": null,
                  "gates": []
               },
               "environmentTriggers": [],
               "badgeUrl": "https://vsrm.dev.azure.com/shaykia/_apis/public/Release/badge/xxxxx5-b891-4fe5-b2fe-9b9a19a1d1af/1/1"
            }
         ],
         "artifacts": [
            {
               "sourceId": "xxxxx-b891-4fe5-b2fe-9b9a19a1d1af:2",
               "type": "Build",
               "alias": "MyProject",
               "definitionReference": {
                  "artifactSourceDefinitionUrl": {
                     "id": "https://dev.azure.com/shaykia/_permalink/_build/index?collectionId=xxxxxx-8c69-4ea0-8882-6340bf42f3b6&projectId=7fcdafd5-b891-4fe5-b2fe-9b9a19a1d1af&definitionId=2",
                     "name": ""
                  },
                  "defaultVersionBranch": {
                     "id": "",
                     "name": ""
                  },
                  "defaultVersionSpecific": {
                     "id": "",
                     "name": ""
                  },
                  "defaultVersionTags": {
                     "id": "",
                     "name": ""
                  },
                  "defaultVersionType": {
                     "id": "latestType",
                     "name": "Latest"
                  },
                  "definition": {
                     "id": "2",
                     "name": "MyBuild"
                  },
                  "project": {
                     "id": "xxxxxx-b891-4fe5-b2fe-9b9a19a1d1af",
                     "name": "SampleForVSTS"
                  }
               },
               "isPrimary": true,
               "isRetained": false
            }
         ],
         "releaseNameFormat": "Release-$(rev:r)",
         "retentionPolicy": {
            "daysToKeep": 30
         },
         "properties": {},
         "id": 1,
         "name": "New Release Definition",
         "path": "\",
         "projectReference": null,
         "url": "https://vsrm.dev.azure.com/shaykia/xxxxxx-b891-4fe5-b2fe-9b9a19a1d1af/_apis/Release/definitions/1",
         "_links": {
            "self": {
               "href": "https://vsrm.dev.azure.com/shaykia/xxxxxx-b891-4fe5-b2fe-9b9a19a1d1af/_apis/Release/definitions/1"
            },
            "web": {
               "href": "https://dev.azure.com/shaykia/xxxxxx-b891-4fe5-b2fe-9b9a19a1d1af/_release?definitionId=1"
            }
         }
      }
   ]
}