Столкновение с проблемой при создании конвейера выпуска ADO - с помощью PowerShell ADO rest API.

Ниже приведен код -

[string]$organisation = "",
[string]$project = "",
[string]$keepForever = "true", 
[string]$user = "", 
[string]$token = "") 

$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $user,$token)))

$postresults = "https://vsrm.dev.azure.com/$organisation/$project/_apis/release/definitions?api-version=5.0" 

$body = @{
  "name"="New release pipeline russ"
  "comment"="test"
  "environments"=@{
    "name"="DEV"

  }
  "path"="\\"
  "releaseNameFormat"="Release"
  "description"=""
} | ConvertTo-Json

$result = Invoke-RestMethod -Uri $postresults -Method Post -Body $body -ContentType "application/json" -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)}

И ошибка, которую я получил -


Invoke-RestMethod : {"$id":"1","innerException":null,"message":"VS402875: 
Release pipeline needs to have at least one stage. Add a stage and try again.",
"typeName":"Microsoft.VisualStudio.Services.ReleaseManagement.Data.Exceptions.I
nvalidRequestException, Microsoft.VisualStudio.Services.ReleaseManagement2.Data
","typeKey":"InvalidRequestException","errorCode":0,"eventId":3000}
At line:27 char:1

Обнаружил аналогичную проблему в блоге сообщества разработчиков VS, к сожалению, в этом нет никакой помощи -

https://developercommunity.visualstudio.com/content/problem/582209/post-example-to-create-a-release-pipeline.html

Любые входы очень ценятся.

Благодарность,

2
Abraham Dhanyaraj 14 Июн 2020 в 23:38

1 ответ

Лучший ответ

environments в теле должно включать как минимум name, preDeployApprovals, postDeployApprovals, deployPhases, retentionPolicy, иначе вы получите ошибку . Тело должно выглядеть так:

{
  "name": "New release pipeline russ",
  "comment": "test",
  "environments": [
    {
      "name": "PROD",
      "preDeployApprovals": {
        "approvals": [
          {
            "rank": 1,
            "isAutomated": false,
            "isNotificationOn": false,
            "approver": {
              "displayName": null,
              "id": "aeb95c63-4fac-4948-84ce-711b0a9dda97"
            },
            "id": 0
          }
        ]
      },
      "postDeployApprovals": {
        "approvals": [
          {
            "rank": 1,
            "isAutomated": true,
            "isNotificationOn": false,
            "id": 0
          }
        ]
      },
      "deployPhases": [
        {
          "deploymentInput": {
            "parallelExecution": {
              "parallelExecutionType": "none"
            },
            "skipArtifactsDownload": false,
            "artifactsDownloadInput": {},
            "queueId": 391,
            "demands": [],
            "enableAccessToken": false,
            "timeoutInMinutes": 0,
            "jobCancelTimeoutInMinutes": 1,
            "condition": "succeeded()",
            "overrideInputs": {}
          },
          "rank": 1,
          "phaseType": "agentBasedDeployment",
          "name": "Run on agent",
          "workflowTasks": []
        }
      ],
      "retentionPolicy": {
        "daysToKeep": 30,
        "releasesToKeep": 3,
        "retainBuild": true
      }
    }
  ],
  "path": "\\",
  "releaseNameFormat": "Release",
  "description": ""
}
2
Cece Dong - MSFT 15 Июн 2020 в 05:34