I am setting up the PR(created manualy by the users) to autocmoplete using rest api from azure pipeline getting following error, kindly help to resolve the issue. details are bleow
Error:
Invoke-RestMethod: /home/vsts/work/_temp/57dec5bf-46fb-449d-9fd7-86e123fc352e.ps1:50 Line | 50 | … eteResult = Invoke-RestMethod -Method PATCH -Headers $headers -Body $ … |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | {"$id":"1","innerException":null,"message":"Invalid argument | value.\r\nParameter name: Invalid pull request auto complete set by id. | Valid values are either the current user identity id, or an empty guid | (to unset auto | complete).","typeName":"Microsoft.TeamFoundation.SourceControl.WebServer.InvalidArgumentValueException, Microsoft.TeamFoundation.SourceControl.WebServer","typeKey":"InvalidArgumentValueException","errorCode":0,"eventId":0}##[error]PowerShell exited with code '1'.
yaml file :
steps:
- task: PowerShell@2
inputs:
targetType: 'inline'
script: |
\# construct base URLs
$apisUrl = "$($env:SYSTEM_TEAMFOUNDATIONCOLLECTIONURI)$($env:SYSTEM_TEAMPROJECT)/\_apis"
$projectUrl = "$apisUrl/git/repositories/XXXXX"
Write-Output "Print out content of projectUrl $projectUrl"
# create common headers
$headers = @{}
$headers.Add("Authorization", "Bearer $env:SYSTEM_ACCESSTOKEN")
$headers.Add("Content-Type", "application/json")
$baseUrl = "https://dev.azure.com/XXXXX/XXXXXX/_apis/git/pullrequests/XXXX?api-version=6.0"
Write-Output "Print out content of baseUrl $baseUrl"
$pullRequestJsonStr = Invoke-RestMethod -Uri $baseUrl -Headers $headers -Method GET
Write-Output "Print out content of pullRequestJsonStr $pullRequestJsonStr"
$pullRequestObj = ConvertTo-Json $pullRequestJsonStr -Depth 5
Write-Output "pullRequestJsonStr to object $pullRequestObj"
#Write-Output "Print out content of Build.Respository.ID $(Build.Repository.ID)"
$autoCompleteSetId = $pullRequestJsonStr.createdBy.id
Write-Output "*****Print out content of autoCompleteSetId $autoCompleteSetId"
#Auto complete call
$setAutoComplete = @{
"autoCompleteSetBy" = @{
"id" = $autoCompleteSetId
}
# "completionOptions" = @{
# "deleteSourceBranch" = $False
# "bypassPolicy" = $False
# }
}
try {
$setAutoCompleteJson = ($setAutoComplete | ConvertTo-Json -Depth 5)
} catch {
Write-Host "Unable to create json due to $_"
}
Write-Output "Print out content of setAutoCompleteJson $setAutoCompleteJson"
Write-Output "***Sending a REST call to set auto-complete on pull request***"
# REST call to set auto-complete on Pull Request
# if ($autoCompleteSetId -ne $null) {
$pullRequestUpdateUrl = ($projectUrl + '/pullRequests/' + $pullRequestJsonStr.pullRequestId + '?api-version=6.0')
Write-Output "Print out content of pullRequestUpdateUrl $pullRequestUpdateUrl"
$setAutoCompleteResult = Invoke-RestMethod -Method PATCH -Headers $headers -Body $setAutoCompleteJson -Uri $pullRequestUpdateUrl
Write-Output "Pull request set to auto-complete"
# }
# else {
# Write-Output "Pull request already set to auto-complete"
# }
env:
SYSTEM_ACCESSTOKEN: $(System.AccessToken)
displayName: 'PowerShell Script'