简体   繁体   中英

Error while creating azure devops release pipeline - POST rest api

Facing an issue while creating a ADO release pipeline - with powershell ADO rest API.

Below is the code -

[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)}

And the error that I got is --


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

Found similar issue in VS developer community blog, unfortunately no help in it -

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

Any inputs are much appreciate.

Thanks,

The environments in the body should include at least name , preDeployApprovals , postDeployApprovals , deployPhases , retentionPolicy , otherwise, you'll get error. The body should look like below:

{
  "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": ""
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM