Reputation: 99
The following script tries to import multiple json files to Azure DevOps Pipeline Release.
$JsonNames = Get-ChildItem C:\Users\path\Downloads\*.json | Select-Object -ExpandProperty Name
ForEach ($JN in $JsonNames)
{
$token = "PAT"
$url = "https://vsrm.dev.azure.com/{organizationName}/{ProjectName}/_apis/release/definitions?api-version=6.0"
$token = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($token)"))
$JSON= Get-Content "C:\Users\<UserName>\Desktop\$($JN).json"
echo $JSON
$response = Invoke-RestMethod -Uri $url -Headers @{Authorization = "Basic $token"} -Method Post -ContentType application/json -body $JSON
}
I receive the following error message. I have used the Get Rest API to get a new a new release definition, updated the project and build id but still receive this error message. Is there a way that the script ignores the Artifact ID?
Invoke-RestMethod : {"$id":"1","innerException":null,"message":"VS402962: No artifact version ID is specified corresponding to artifact source 'Test'. Specify
a valid value and try again.","typeName":"Microsoft.VisualStudio.Services.ReleaseManagement.Data.Exceptions.InvalidRequestException,
Microsoft.VisualStudio.Services.ReleaseManagement2.Data","typeKey":"InvalidRequestException","errorCode":0,"eventId":3000}
At line:19 char:13
+ $response = Invoke-RestMethod -Uri $url -Headers @{Authorization = "B ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
Upvotes: 0
Views: 620
Reputation: 35139
Based on my test, when you try to upload the json files to release pipeline, you only need to change the queueid and release Definition ID.
For example: change queueId and the release id before the release definition name.
"downloadInputs":[]},"queueId":227,"demands":
"IntegrateJiraWorkItems":{"$type":"System.String","$value":"false"}},"id":10,"name":"New release pipeline (511)","path":"\\"
Although you have to upload release definition json in different projects, you still don’t need to change the buildid and projectid.
Then the same script will successfully create release.
VS402962: No artifact version ID is specified corresponding to artifact source 'Test'. Specify a valid value and try again
According to the error message, you could check the version of the build artifacts in the original release pipeline. You need to make sure that the version of the artifacts exists.
Upvotes: 1