Azure DevOps REST API创建发布定义 [英] Azure DevOps REST API to create a release definition

本文介绍了Azure DevOps REST API创建发布定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Azure DevOps REST API创建版本定义.我创建了一个json文件,其中包含该请求的配置详细信息.创建发行版定义时出现以下错误.

I'm trying to create a release definition by using Azure DevOps REST API. I've created a json file which has configuration details for the request. I'm getting the below error, while creating the release definition.

{
    "$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云中创建新的版本定义.

I'm using the below request body to create a new release definition in Azure cloud.

<代码>{"name":"myreleasedefn1",工件":[{"type":"DockerHub","alias":"_dockerusername_mydockerimage","definitionReference":{联系": {"id":"dd986f4a-123k-45d5-b8e6-fc4fds23rce","name":"dockerservice"},"defaultVersionType":{"id":"selectDuringReleaseCreationType","name":在创建发行版时指定"},定义": {"id":"dockerusername/mydockerimage","name":"dockerusername/mydockerimage"},命名空间":{"id":"dockerusername","name":"dockerusername"}},"isPrimary":是的,"isRetained":false}],"releaseNameFormat":发布-$(rev:r)",环境":[{"name":发展",等级":1"retentionPolicy":{"daysToKeep":30,"releasesToKeep":3,"retainBuild":正确},"preDeployApprovals":{批准":[{等级":1"isAutomated":是的,"isNotificationOn":否,"id":10}],"approvalOptions":{"requiredApproverCount":null,"releaseCreatorCanBeApprover":否,"autoTriggeredAndPreviousEnvironmentApprovedCanBeSkipped":否,"enforceIdentityRevalidation":否,"timeoutInMinutes":0,"executionOrder":"beforeGates"}},"postDeployApprovals":{批准":[{等级":1"isAutomated":是的,"isNotificationOn":否,"id":12}],"approvalOptions":{"requiredApproverCount":null,"releaseCreatorCanBeApprover":否,"autoTriggeredAndPreviousEnvironmentApprovedCanBeSkipped":否,"enforceIdentityRevalidation":否,"timeoutInMinutes":0,"executionOrder":"afterSuccessfulGates"}},"deployPhases":[{"deploymentInput":{"parallelExecution":{"parallelExecutionType":无"},"agentSpecification":{"identifier":"ubuntu-16.04"},"skipArtifactsDownload":否,"artifactsDownloadInput":{"downloadInputs":[]},"queueId":9需要": [],"enableAccessToken":否,"timeoutInMinutes":0,"jobCancelTimeoutInMinutes":1"condition":"succeeded()","overrideInputs":{}},等级":1"phaseType":"agentBasedDeployment","name":在代理上运行","workflowTasks":[{"version":"4. *","name":部署Azure App Service","refName":",已启用":是,"alwaysRun":false,"continueOnError":否,"timeoutInMinutes":0,"overrideInputs":{},"condition":"succeeded()",输入":{"ConnectionType":"AzureRM","WebAppKind":"webAppContainer","WebAppName":"azureappservice1","DeployToSlotOrASEFlag":"false","ResourceGroupName":","SlotName":生产","DockerNamespace":"dockerusername","DockerRepository":"mydockerimage","DockerImageTag":"10"
}}]}]}]}

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

It would be very helpful if you share an example template for the same request. Please help!!!

推荐答案

使用Azure DevOps REST API创建发布定义

Azure DevOps REST API to create a release definition

根据错误消息:

"Workflow of deploy job 'Run on the agent' in release pipeline stage 'development' is invalid.

我们可能知道 workflowTasks 中的任务 Deploy Azure App Service 无效,我们需要为该任务提供正确的请求正文.

We could to know the task Deploy Azure App Service in the workflowTasks is invalid, we need to provide the correct request body for that task.

当我回答您以前的帖子时如何使用Azure DevOps REST API 创建新的构建管道,如果我们完全手动添加一个巨大的请求主体,这将非常困难且容易出错.通常,我们使用REST API 定义-获取从类似的发布管道中获取响应主体,然后我们通过修改响应主体来更新相应的属性.

As I answered your previous post How to create new build pipeline using Azure DevOps REST API, this is very difficult and error-prone, if we add a huge request body completely manually. Usually, we use REST API Definitions - Get to get the Response Body from the similar release pipeline, then we update the corresponding properties by modifying the Response Body.

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

As test, I add the task Deploy Azure App Service in my release pipeline, then I use the REST API:

GET https://vsrm.dev.azure.com/{organization}/{project}/_apis/release/definitions/{definitionId}?api-version=5.0

获取响应正文:

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

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

You could use this response body, and overwrite those properties you want to change.

我在Azure门户中哪里可以获得taskId?

Where can I get taskId in Azure portal?

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

You could check the source code of the task from Github,it is generally on the first line of task.json. Or you can use REST API/F12 to get it.

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

Can we use 'AzureContainerRegistry' as artifact type in the request body?

答案应该是(不通过样本进行测试).您可以在正文中添加以下请求正文:

The answer should be yes (not test it by a sample). You could add following request body in the body:

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

希望这会有所帮助.

这篇关于Azure DevOps REST API创建发布定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆