我正在使用Azure Devops Services REST API 5.0来更新管道发布。
我有一个舞台开发的发行版,该舞台开发中有两个任务,在"代理"作业中:
- 部署Plataform 1
- 部署Plataform 2
我想使用Azure Devops Services REST API的更新方法添加一个新任务"部署Plataform 3"。
但是,当我尝试更新时,有错误: 我使用URL获取发布定义: 我在对象 put url: 错误: put方法: 使用此PUT方法,我可以成功修改现有任务名称(部署Plataform 1 =>部署Plataform X(。但无法添加新任务。 这是一个错误,或者我缺少一些东西。
具有版本的"部署Plataform 3:1">https://vsrm.dev.azure.com/organizationname/projectname/_apis/release/definitions/5?api-version=5.0
environments[0].deployPhases[0].workflowTasks
中添加了一个新任务。Workflowtasks
对象带有我的新任务:"workflowTasks": [
{
"environment": {},
"taskId": "501dd25d-1785-43e4-b4e5-a5c78ccc0573",
"version": "1.*",
"name": "Deploy Plataform 1",
"refName": "",
"enabled": true,
"alwaysRun": false,
"continueOnError": false,
"timeoutInMinutes": 0,
"definitionType": null,
"overrideInputs": {},
"condition": "succeeded()",
"inputs": {
"azureSubscription": "3ca9b800-e82b-4678-8483-xxxxx",
"appType": "$(Parameters.AppType)",
"appName": "app func name 1",
"deployToSlotOrASE": "false",
"resourceGroupName": "",
"slotName": "production",
"package": "$(System.DefaultWorkingDirectory)/**/*.zip",
"runtimeStack": "",
"startUpCommand": "",
"customWebConfig": "",
"appSettings": "",
"configurationStrings": "",
"deploymentMethod": "auto"
}
},
{ ...
},
{
"environment": {},
"taskId": "502dd25d-1785-43e4-b4e5-a5c78ccc0573",
"version": "1.*",
"name": "Deploy Plataform 3",
"refName": "",
"enabled": true,
"alwaysRun": false,
"continueOnError": false,
"timeoutInMinutes": 0,
"definitionType": "task",
"overrideInputs": {},
"condition": "succeeded()",
"inputs": {
"azureSubscription": "3ca9b844-e92b-4678-8483-xxxx",
"appType": "functionApp",
"appName": "func app name",
"deployToSlotOrASE": "false",
"resourceGroupName": "",
"slotName": "production",
"package": "$(System.DefaultWorkingDirectory)/**/*.zip",
"runtimeStack": "",
"startUpCommand": "",
"customWebConfig": "",
"appSettings": "",
"configurationStrings": "",
"deploymentMethod": "auto"
}
}
]
https://vsrm.dev.azure.com/{organization}/{project}/_apis/release/definitions?api-version=5.0
Invoke-RestMethod : {"$id":"1","innerException":null,"message":"Tasks with versions 'Deploy Plataform 3:1.*' are not valid for deploy job 'Run on agent' in stage DEV.
","typeName":"Microsoft.VisualStudio.Services.ReleaseManagement.Data.Exceptions.InvalidRequestException, Microsoft.VisualStudio.Services.ReleaseManagement2.Data","typeKey":"InvalidRequestException","errorCode":0,"eventId":3000}
Au caractère C:ProjectsTransportConfigurationAutomationTasksBuild Definitions Supporting ScriptsUpdate-Release-Stage.ps1:49 : 9
+ Invoke-RestMethod -Uri $uri -Headers ($Header) -Method PUT -B ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation : (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
function Invoke-WebRequestPut ([PSCustomObject] $releaseDefinition) {
$uri = "https://vsrm.dev.azure.com/organizationname/projectname/_apis/release/definitions?api-version=5.0"
$Auth = '{0}:{1}' -f $UserName, $PersonalToken
$Auth = [System.Text.Encoding]::UTF8.GetBytes($Auth)
$Auth = [System.Convert]::ToBase64String($Auth)
$Header = @{Authorization = ("Basic {0}" -f $Auth)}
$body = $releaseDefinition | ConvertTo-Json -Depth 30
$body2 = [System.Text.Encoding]::UTF8.GetBytes($body)
Invoke-RestMethod -Uri $uri -Headers ($Header) -Method PUT -Body $body2 -ContentType "application/json"
}
我找到了问题。
我添加的新WorkflowTask
具有我要生成的字段taskId
。但是,此taskId
字段对应于我要使用的 azure管道任务类型。就我而言,我需要设置 azure函数应用程序任务ID,501dd25d-1785-43e4-b4e5-a5c78ccc0573
。
WorkFlowTask的文档尚未完成,我们只有:TaskId: string