首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Azure DevOps REST创建发布定义

Azure DevOps REST创建发布定义
EN

Stack Overflow用户
提问于 2020-02-07 10:09:57
回答 2查看 2.5K关注 0票数 2

我试图使用Azure DevOps REST创建一个发布定义。我已经创建了一个包含请求配置细节的json文件。在创建发布定义时,我得到了下面的错误。

代码语言:javascript
运行
复制
{
    "$id": "1",
    "innerException": null,
    "message": "Workflow of deploy job 'Run on the agent' in release pipeline stage 'development' is invalid. Add valid tasks and try again.",
    "typeName": "Microsoft.VisualStudio.Services.ReleaseManagement.Data.Exceptions.InvalidRequestException, Microsoft.VisualStudio.Services.ReleaseManagement2.Data",
    "typeKey": "InvalidRequestException",
    "errorCode": 0,
    "eventId": 3000 
}

我正在使用下面的请求体在Azure云中创建一个新的发布定义。

{ "name": "myreleasedefn1", "artifacts": [{ "type": "DockerHub", "alias": "_dockerusername_mydockerimage", "definitionReference": { "connection": { "id": "dd986f4a-123k-45d5-b8e6-fc4fds23rce", "name": "dockerservice" }, "defaultVersionType": { "id": "selectDuringReleaseCreationType", "name": "Specify at the time of release creation" }, "definition": { "id": "dockerusername/mydockerimage", "name": "dockerusername/mydockerimage" }, "namespaces": { "id": "dockerusername", "name": "dockerusername" } }, "isPrimary": true, "isRetained": false }], "releaseNameFormat": "Release-$(rev:r)", "environments": [{ "name": "development", "rank": 1, "retentionPolicy": { "daysToKeep": 30, "releasesToKeep": 3, "retainBuild": true }, "preDeployApprovals": { "approvals": [ { "rank": 1, "isAutomated": true, "isNotificationOn": false, "id": 10 } ], "approvalOptions": { "requiredApproverCount": null, "releaseCreatorCanBeApprover": false, "autoTriggeredAndPreviousEnvironmentApprovedCanBeSkipped": false, "enforceIdentityRevalidation": false, "timeoutInMinutes": 0, "executionOrder": "beforeGates" } }, "postDeployApprovals": { "approvals": [ { "rank": 1, "isAutomated": true, "isNotificationOn": false, "id": 12 } ], "approvalOptions": { "requiredApproverCount": null, "releaseCreatorCanBeApprover": false, "autoTriggeredAndPreviousEnvironmentApprovedCanBeSkipped": false, "enforceIdentityRevalidation": false, "timeoutInMinutes": 0, "executionOrder": "afterSuccessfulGates" } }, "deployPhases": [{ "deploymentInput": { "parallelExecution": { "parallelExecutionType": "none" }, "agentSpecification": { "identifier": "ubuntu-16.04" }, "skipArtifactsDownload": false, "artifactsDownloadInput": { "downloadInputs": [] }, "queueId": 9, "demands": [], "enableAccessToken": false, "timeoutInMinutes": 0, "jobCancelTimeoutInMinutes": 1, "condition": "succeeded()", "overrideInputs": {} }, "rank": 1, "phaseType": "agentBasedDeployment", "name": "Run on the agent", "workflowTasks": [{ "version": "4.*", "name": "Deploy Azure App Service", "refName": "", "enabled": true, "alwaysRun": false, "continueOnError": false, "timeoutInMinutes": 0, "overrideInputs": {}, "condition": "succeeded()", "inputs": { "ConnectionType": "AzureRM", "WebAppKind": "webAppContainer", "WebAppName": "azureappservice1", "DeployToSlotOrASEFlag": "false", "ResourceGroupName": "", "SlotName": "production", "DockerNamespace": "dockerusername", "DockerRepository": "mydockerimage", "DockerImageTag": "10"

代码语言:javascript
运行
复制
             `}             }]         }]     }] }`

如果您为同一个请求共享一个示例模板,这将非常有帮助。救命啊!

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2020-02-10 03:40:29

Azure DevOps REST创建发布定义

根据错误消息:

代码语言:javascript
运行
复制
"Workflow of deploy job 'Run on the agent' in release pipeline stage 'development' is invalid.

我们可以知道任务Deploy Azure App ServiceworkflowTasks中是无效的,我们需要为该任务提供正确的请求体。

我回答了您上一篇文章如何使用Azure DevOps REST创建新的构建管道,如果我们完全手动添加一个庞大的请求体,这是非常困难和容易出错的。通常,我们使用REST 定义-获取从类似的发布管道中获取响应体,然后通过修改响应体更新相应的属性。

作为测试,我在发布管道中添加了部署Azure API的任务,然后使用REST:

代码语言:javascript
运行
复制
GET https://vsrm.dev.azure.com/{organization}/{project}/_apis/release/definitions/{definitionId}?api-version=5.0

要获得响应体:

代码语言:javascript
运行
复制
                "workflowTasks": [
                    {
                        "environment": {},
                        "taskId": "497d490f-eea7-4f2b-ab94-48d9c1acdcb1",
                        "version": "4.*",
                        "name": "Azure App Service Deploy: xxxx",
                        "refName": "",
                        "enabled": true,
                        "alwaysRun": false,
                        "continueOnError": false,
                        "timeoutInMinutes": 0,
                        "definitionType": "task",
                        "overrideInputs": {},
                        "condition": "succeeded()",
                        "inputs": {
                            "ConnectionType": "AzureRM",
                            "ConnectedServiceName": "xxxxx",
                            "PublishProfilePath": "$(System.DefaultWorkingDirectory)/**/*.pubxml",
                            "PublishProfilePassword": "",
                            "WebAppKind": "webApp",
                            "WebAppName": "xxxx",
                            "DeployToSlotOrASEFlag": "false",
                            "ResourceGroupName": "",
                            "SlotName": "production",
                            "DockerNamespace": "",
                            "DockerRepository": "",
                            "DockerImageTag": "",
                            "VirtualApplication": "",
                            "Package": "$(System.DefaultWorkingDirectory)/**/*.zip",
                            "RuntimeStack": "",
                            "RuntimeStackFunction": "",
                            "StartupCommand": "",
                            "ScriptType": "",
                            "InlineScript": ":: You can provide your deployment commands here. One command per line.",
                            "ScriptPath": "",
                            "WebConfigParameters": "",
                            "AppSettings": "",
                            "ConfigurationSettings": "",
                            "UseWebDeploy": "false",
                            "DeploymentType": "webDeploy",
                            "TakeAppOfflineFlag": "true",
                            "SetParametersFile": "",
                            "RemoveAdditionalFilesFlag": "false",
                            "ExcludeFilesFromAppDataFlag": "true",
                            "AdditionalArguments": "-retryAttempts:6 -retryInterval:10000",
                            "RenameFilesFlag": "true",
                            "XmlTransformation": "false",
                            "XmlVariableSubstitution": "false",
                            "JSONFiles": ""
                        }
                    }
                ]

您可以使用此响应体,并覆盖要更改的那些属性。

在Azure门户网站上我可以在哪里获得taskId?

您可以从Github检查任务的源代码,它通常位于task.json的第一行。或者您可以使用REST /F12来获得它。

我们可以在请求体中使用'AzureContainerRegistry‘作为工件类型吗?

答案应该是“是”(而不是用样本来测试)。可以在正文中添加以下请求正文:

代码语言:javascript
运行
复制
"artifacts": [
    {
        "sourceId": "xxxxxxxxxxxxxxx",
        "type": "AzureContainerRepository",
        "alias": "xxx",
        "definitionReference": {
            "connection": {
                "id": "xxxxxx",
                "name": "xxxx"
            },
            "defaultVersionType": {
                "id": "latestType",
                "name": "Latest"
            },
            "definition": {
                "id": "xx",
                "name": "xx"
            },
            "registryurl": {
                "id": "22",
                "name": "22"
            },
            "resourcegroup": {
                "id": "xx",
                "name": "xx"
            }
        },
        "isPrimary": true,
        "isRetained": false
    }
],

希望这能有所帮助。

票数 2
EN

Stack Overflow用户

发布于 2020-02-08 04:18:47

我能帮上忙。在workflowTasks中,您需要包含"taskId": "497d490f-eea7-4f2b-ab94-48d9c1acdcb1",它是AzureRmWebAppDeploymentV4的id。

代码语言:javascript
运行
复制
"workflowTasks": [
            {
              "taskId": "497d490f-eea7-4f2b-ab94-48d9c1acdcb1",
              "version": "4.*",
              "name": "Deploy Azure App Service",
              "refName": "",
              "enabled": true,
              "alwaysRun": false,
              "continueOnError": false,
              "timeoutInMinutes": 0,
              "definitionType": null,
              "overrideInputs": {},
              "condition": "succeeded()",
              "inputs": {
                  "ConnectionType": "AzureRM",
                  "WebAppKind": "webAppContainer",
                  "WebAppName": "azureappservice1",
                  "DeployToSlotOrASEFlag": "false",
                  "ResourceGroupName": "",
                  "SlotName": "production",
                  "DockerNamespace": "dockerusername",
                  "DockerRepository": "mydockerimage",
                  "DockerImageTag": "10"

              }

有一次我补充说,我能够用您的请求体创建发布定义。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60111255

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档