VSTS:如何在返回的版本定义中扩展所有属性

时间:2018-09-25 16:09:03

标签: azure-devops azure-devops-rest-api

我们的VSTS体系结构使用单个发布管道来升级和启动其他管道。在踢出的管道运行发行版之前,“ kicker”管道会更新“ kickee”管道的发行版定义。我只有“ kickee”管道的名称,而没有ID,因此要升级管道,我们调用在以下位置记录的API:

https://docs.microsoft.com/en-us/rest/api/vsts/release/definitions/list?view=vsts-rest-5.0#releasedefinitionexpands

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

2 个答案:

答案 0 :(得分:1)

您用,分隔属性。

例如:

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"
            }
         }
      }
   ]
}

答案 1 :(得分:0)

我通过使用列表API来获取定义ID,然后调用get API来获取特定发行版定义的全部内容来解决该问题。如果我需要一次更新大量的发行版定义,这不是理想的选择,但是由于我一次只需要更新一个定义,因此可以满足我的需求。