azure-devops - 用于创建发布定义的 Azure DevOps REST API
问题描述
我正在尝试使用 Azure DevOps REST API 创建发布定义。我创建了一个 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"
}
}]
}]
}]
}
如果您为同一请求共享示例模板,这将非常有帮助。请帮忙!!!
解决方案
用于创建发布定义的 Azure DevOps REST API
根据错误信息:
"Workflow of deploy job 'Run on the agent' in release pipeline stage 'development' is invalid.
我们可以知道其中的任务Deploy Azure App Service
是workflowTasks
无效的,我们需要为该任务提供正确的请求正文。
正如我回答您之前的帖子How to create new build pipeline using Azure DevOps REST API一样,如果我们完全手动添加巨大的请求正文,这将非常困难且容易出错。通常,我们使用 REST API Definitions - Get从类似的发布管道中获取响应体,然后我们通过修改响应体来更新相应的属性。
作为测试,我在我的发布管道中添加了部署 Azure 应用服务的任务,然后我使用了 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": ""
}
}
]
您可以使用此响应正文,并覆盖您想要更改的那些属性。
在 Azure 门户中的哪里可以获取 taskId?
你可以在 Github 上查看任务的源代码,一般在task.json
. 或者您可以使用 REST API/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
}
],
希望这可以帮助。
推荐阅读
- c# - 将现有用户表与实体中的 asp.net 用户表连接的问题
- macos - Flutter - 如何在 MacOS 应用程序中使用 smb 映射网络驱动器?
- angular - 如何动态更改(完全替换)GoJS 中的 diagram.model?
- python-3.x - 如何在字符串中查找包含没有任何后缀和前缀的字符串的行?
- artifactory - 禁用修订时,无法将柯南包上传到 Artifactory 服务器
- c - C. double数组和char数组中realloc的区别
- c++ - doopen():“无法从共享对象映射段”当不以root身份运行时
- javascript - createjs off() 函数从 js 箭头函数中删除监听器
- java - Java 8:转换地图
> 到地图 - ios - 如何检测iOS中音量的变化?