Reputation: 949
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 -
Any inputs are much appreciate .
Thanks,
Upvotes: 2
Views: 1608
Reputation: 31093
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": ""
}
Upvotes: 2