我试图使用Azure DevOps REST创建一个发布定义。我已经创建了一个包含请求配置细节的json文件。在创建发布定义时,我得到了下面的错误。
{
"$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"
`} }] }] }] }`
如果您为同一个请求共享一个示例模板,这将非常有帮助。救命啊!
发布于 2020-02-10 03:40:29
Azure DevOps REST创建发布定义
根据错误消息:
"Workflow of deploy job 'Run on the agent' in release pipeline stage 'development' is invalid.
我们可以知道任务Deploy Azure App Service
在workflowTasks
中是无效的,我们需要为该任务提供正确的请求体。
我回答了您上一篇文章如何使用Azure DevOps REST创建新的构建管道,如果我们完全手动添加一个庞大的请求体,这是非常困难和容易出错的。通常,我们使用REST 定义-获取从类似的发布管道中获取响应体,然后通过修改响应体更新相应的属性。
作为测试,我在发布管道中添加了部署Azure API的任务,然后使用REST:
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": ""
}
}
]
您可以使用此响应体,并覆盖要更改的那些属性。
在Azure门户网站上我可以在哪里获得taskId?
您可以从Github检查任务的源代码,它通常位于task.json
的第一行。或者您可以使用REST /F12来获得它。
我们可以在请求体中使用'AzureContainerRegistry‘作为工件类型吗?
答案应该是“是”(而不是用样本来测试)。可以在正文中添加以下请求正文:
"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
}
],
希望这能有所帮助。
发布于 2020-02-08 04:18:47
我能帮上忙。在workflowTasks
中,您需要包含"taskId": "497d490f-eea7-4f2b-ab94-48d9c1acdcb1"
,它是AzureRmWebAppDeploymentV4的id。
"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"
}
有一次我补充说,我能够用您的请求体创建发布定义。
https://stackoverflow.com/questions/60111255
复制相似问题