azure - 更新azure devops发布管道: Tasks with versions 'Deploy Plataform 3:1.*' are not valid for deploy job 'Run on agent'

标签 azure azure-functions azure-devops-rest-api

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

我有一个带有阶段 DEV 的版本,该版本在“在代理上运行”作业中有两个任务:

  • 部署平台 1
  • 部署平台 2

我想使用 update method 添加新任务“部署平台 3”来自 Azure DevOps 服务 REST API。

但是当我尝试更新时出现错误:
版本为“部署平台 3:1.*”的任务对于阶段 DEV 中的部署作业“在代理上运行”无效。

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

放置网址: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 任务 类型。就我而言,我需要设置azure function app任务ID,501dd25d-1785-43e4-b4e5-a5c78ccc0573

documentation对于 WorkflowTask 并不完整,我们只有: TaskId: string

关于azure - 更新azure devops发布管道: Tasks with versions 'Deploy Plataform 3:1.*' are not valid for deploy job 'Run on agent' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56261427/

相关文章:

python - 使用 VS Code 即时运行 Azure Functions 失败并显示 ECONNREFUSED

c# - 配置服务时如何通过依赖注入(inject)在 Azure Function V3 中注入(inject)或使用 IConfiguration

用户注册后的Azure B2C回调: Basic credentials specified for 'PreUserWriteRestful' are invalid

c# - 为什么我在使用个人访问 token 时收到授权错误?

python - 如何使用 python 访问 Azure Dev Ops 数据,例如日期之间的变更集?

Azure B2C 自定义策略 : How do you reset the TOTP settings in the event that a user lost access to there authenticator app?

powershell - Azure Powershell Cmdlet 和证书过期

AZURE PIPELINE 将变量从一个脚本传递到另一个脚本

python - 限制 Azure 应用程序访问 OneDrive 中的特定文件夹

azure-devops - Azure DevOps 如何通过 REST API 编辑 Wiki 页面