Trigger release pipeline using rest API not working

Copper Contributor

Hi 

 

I want to trigger release pipeline using Rest API. I have the script in PowerShell and I am trying to follow this document

 

https://docs.microsoft.com/en-us/rest/api/azure/devops/release/releases/create?view=azure-devops-res...

 

 

$AccountName = 'msazure';
$ProjectName = 'TestProject';
$ReleaseDefinitionId = '1234'
$BuildDefinitionId = '123456'
$BuildId = '12345678'

$headers = $auth + @{
"Content-Type" = "application/json";
"Accept" = "application/json";
}

$buildVersion = @{
id = $BuildId;
definitionId = $BuildDefinitionId;
} | ConvertTo-Json

$instanceReference = @{
alias = "Library-Official";
instanceReference = $buildVersion;
}

$Url = "https://vsrm.dev.azure.com/{0}/{1}/_apis/release/releases?api-version=6.0" -f $AccountName, $ProjectName;
Write-Host "URL = POST $Url";

$rawBody = @(
@{
DefinitionId = $ReleaseDefinitionId;
artifacts = $instanceReference;
isDraft = $false;
reason = "none";
}
)
$Body = ConvertTo-Json -InputObject $rawBody;
Write-Host "Body = $Body";
$Result = Invoke-RestMethod -Method 'Post' -Headers $headers -Uri $url -Body ([System.Text.Encoding]::UTF8.GetBytes($Body))
$Result.value | Format-List -Property *

 

The script completes without any error but the new release is not getting created. How do I determine the correct value for account name, project name and alias of instanceReference. Also do I need to do anything for authentication? What other thing can I do?

 

Thanks

0 Replies