我们有一个 Azure DevOps 管道发布定义,我正在考虑为在分支 x 上触发拉取请求时从模板创建新的“阶段”以及在分支时删除阶段进行一些自动化被删除。我将为此使用 github 操作。
API 文档不是很容易理解。
我的问题是:
这可能吗,API 是否支持对 _releaseDefinition 进行此类添加和删除阶段?
如果是这样,有没有关于如何做到这一点的例子?
我们有一个 Azure DevOps 管道发布定义,我正在考虑为在分支 x 上触发拉取请求时从模板创建新的“阶段”以及在分支时删除阶段进行一些自动化被删除。我将为此使用 github 操作。
API 文档不是很容易理解。
我的问题是:
这可能吗,API 是否支持对 _releaseDefinition 进行此类添加和删除阶段?
如果是这样,有没有关于如何做到这一点的例子?
您应该使用的 api 是Update-definition api:
PUT https://vsrm.dev.azure.com/{org name}/{project name}/_apis/release/definitions?api-version=5.1
添加stage/ removing stage的请求体,其实只是修改了environments
参数:
一个阶段定义对应一个格雷码块。
Adding stage
:添加阶段定义()的模板JSON代码块。the grey one display in my left screenshots
这个代码结构是固定的。
Removing stage
:删除完整的相应阶段定义。
这是一个完整的阶段定义示例:
{
"id": -1,
"name": "Stage 3",
"rank": 3,
"variables": {},
"variableGroups": [],
"preDeployApprovals": {
"approvals": [
{
"rank": 1,
"isAutomated": true,
"isNotificationOn": false,
"id": 7
}
],
"approvalOptions": {
"requiredApproverCount": null,
"releaseCreatorCanBeApprover": false,
"autoTriggeredAndPreviousEnvironmentApprovedCanBeSkipped": false,
"enforceIdentityRevalidation": false,
"timeoutInMinutes": 0,
"executionOrder": "beforeGates"
}
},
"deployStep": {
"id": 8
},
"postDeployApprovals": {
"approvals": [
{
"rank": 1,
"isAutomated": true,
"isNotificationOn": false,
"id": 9
}
],
"approvalOptions": {
"requiredApproverCount": null,
"releaseCreatorCanBeApprover": false,
"autoTriggeredAndPreviousEnvironmentApprovedCanBeSkipped": false,
"enforceIdentityRevalidation": false,
"timeoutInMinutes": 0,
"executionOrder": "afterSuccessfulGates"
}
},
"deployPhases": [
{
"deploymentInput": {
"parallelExecution": {
"parallelExecutionType": "none"
},
"agentSpecification": {
"identifier": "vs2017-win2016"
},
"skipArtifactsDownload": false,
"artifactsDownloadInput": {
"downloadInputs": []
},
"queueId": 247,
"demands": [],
"enableAccessToken": false,
"timeoutInMinutes": 0,
"jobCancelTimeoutInMinutes": 1,
"condition": "succeeded()",
"overrideInputs": {}
},
"rank": 1,
"phaseType": "agentBasedDeployment",
"name": "Agent job",
"refName": null,
"workflowTasks": []
}
],
"environmentOptions": {
"emailNotificationType": "OnlyOnFailure",
"emailRecipients": "release.environment.owner;release.creator",
"skipArtifactsDownload": false,
"timeoutInMinutes": 0,
"enableAccessToken": false,
"publishDeploymentStatus": true,
"badgeEnabled": false,
"autoLinkWorkItems": false,
"pullRequestDeploymentEnabled": false
},
"demands": [],
"conditions": [],
"executionPolicy": {
"concurrencyCount": 1,
"queueDepthCount": 0
},
"schedules": [],
"owner": {
"displayName": "{user name}",
"id": "{user id}",
"isContainer": false,
"uniqueName": "{creator account}",
"url": "https://dev.azure.com/{org name}/"
},
"retentionPolicy": {
"daysToKeep": 30,
"releasesToKeep": 3,
"retainBuild": true
},
"processParameters": {},
"properties": {
"BoardsEnvironmentType": {
"$type": "System.String",
"$value": "unmapped"
},
"LinkBoardsWorkItems": {
"$type": "System.String",
"$value": "False"
}
},
"preDeploymentGates": {
"id": 0,
"gatesOptions": null,
"gates": []
},
"postDeploymentGates": {
"id": 0,
"gatesOptions": null,
"gates": []
},
"environmentTriggers": [],
"badgeUrl": "https://vsrm.dev.azure.com/{org}/_apis/{project name}/Release/badge/3c3xxx6414512/2/3"
},
这里有一些您需要注意的关键参数:id
、owner
和。rank
conditions
id
: 这是你指定的stage id,它的值必须小于1。任何小于 1 的值都可以。
owner
: 这是必需的。或者您将收到通知您舞台必须拥有所有者的消息。
rank
:大于1的自然数。这里建议你根据其他阶段递增。
conditions
:这是您可以配置当前新阶段将依赖于哪个阶段的阶段。简而言之,它用于指定发布的阶段执行位置。
当您更新发布时,您必须将整个发布定义打包并设置为请求正文。获取原始的,将新的自定义阶段定义部分添加到其中。然后更新到api。
事实上,我建议你添加一个带有 UI 的阶段进行测试。然后转到发布定义页面的历史记录选项卡。然后选择Compare difference
三个点。
我们在面板(left panel is the original, the right is updated
)中为您提供了定义的差异,您可以清楚地了解应用您的想法应该关注的内容。