更新 azure devops 发布管道:版本 'Deploy Plataform 3:1.*' 的任务对于部署作业 'Run on agent' 无效

Update azure devops release pipeline: Tasks with versions 'Deploy Plataform 3:1.*' are not valid for deploy job 'Run on agent'

我正在使用 Azure DevOps Services REST API 5.0 来更新管道版本。

我有一个带有阶段 DEV 的版本,在 'Run on agent' 作业中有两个任务:

我想使用来自 Azure DevOps Services REST API 的 update method 添加一个新任务 'Deploy plataform 3'。

但是当我尝试更新时出现错误:
版本为 'Deploy Plataform 3:1.*' 的任务对于阶段 DEV 中的部署作业 'Run on agent' 无效。

get使用url的发布定义: 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"
        }
    }
]

PUT url: 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:\Projects\TransportConfiguration\AutomationTasks\Build Definitions Supporting Scripts\Update-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"
}

使用此 put 方法我可以成功修改现有任务名称(部署平台 1 => 部署平台 X)。但是无法添加新任务。

这是一个错误,或者我遗漏了什么。

我发现了问题。
我添加的新 WorkflowTask 有一个我试图生成的字段 taskId。但是这个taskId字段对应的是我要使用的azure pipeline task类型。在我的例子中,我需要设置 azure function app task id,501dd25d-1785-43e4-b4e5-a5c78ccc0573.

WorkflowTask 的 documentation 不完整,我们只有:TaskId: string