Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Azure devops Azure DevOps管道-发布API-更新发布定义添加和删除模板化阶段_Azure Devops_Azure Pipelines_Azure Pipelines Release Pipeline_Azure Pipelines Release Task - Fatal编程技术网

Azure devops Azure DevOps管道-发布API-更新发布定义添加和删除模板化阶段

Azure devops Azure DevOps管道-发布API-更新发布定义添加和删除模板化阶段,azure-devops,azure-pipelines,azure-pipelines-release-pipeline,azure-pipelines-release-task,Azure Devops,Azure Pipelines,Azure Pipelines Release Pipeline,Azure Pipelines Release Task,我们有一个Azure DevOps管道发布定义,我正在考虑在分支x上触发拉取请求时从模板创建一个新的“阶段”,并在删除分支时删除该阶段。我将为此使用github操作 API文档不是非常容易遵循的 我的问题是: 这是否可能,API是否支持在发布定义中添加和删除阶段 如果有,有没有关于如何做到这一点的例子 医生的 您应该使用的api是: 对于添加阶段/删除阶段的请求主体,实际上只对环境参数进行了更改: 一个阶段定义对应一个灰色代码块 添加阶段:添加阶段定义的模板JSON代码块。灰色代码块显示在我的左

我们有一个Azure DevOps管道发布定义,我正在考虑在分支x上触发拉取请求时从模板创建一个新的“阶段”,并在删除分支时删除该阶段。我将为此使用github操作

API文档不是非常容易遵循的

我的问题是:

这是否可能,API是否支持在发布定义中添加和删除阶段

如果有,有没有关于如何做到这一点的例子

医生的 您应该使用的api是:

对于添加阶段/删除阶段的请求主体,实际上只对环境参数进行了更改:

一个阶段定义对应一个灰色代码块

添加阶段:添加阶段定义的模板JSON代码块。灰色代码块显示在我的左侧屏幕截图中。这个代码结构是固定的

删除阶段:删除完整的相应阶段定义

以下是一个完整的阶段定义示例:

 {
            "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、所有者、等级和条件

id:这是指定给stage的stage id,其值必须小于1。这里任何小于1的值都可以

所有者:这是必需的。或者,您将收到一条消息,通知您该阶段必须拥有所有者

等级:大于1的自然数。在这里,我建议您在其他阶段的基础上增加它

条件:这是您可以配置当前新阶段所依赖的阶段。简而言之,它用于指定发布的阶段执行位置

更新发布时,必须将整个发布定义打包并设置为请求正文。获取原始的,添加新的自定义阶段定义部分。然后更新到api

事实上,我建议您添加一个带有UI的测试阶段。然后转到“发布定义”页面的“历史记录”选项卡。然后选择比较三个点的差异


我们在面板中为您提供了不同的定义左面板是原始面板,右面板是更新的,您可以清楚地了解应用您的想法时应该关注的内容。

您现在有成功的工作吗?我可以了解一下这个项目的情况吗?这对你有帮助吗?如果是,您可以这样做,以便其他用户能够看到该解决方案是否有效:-
 {
            "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"
        },