Last active
March 30, 2019 05:16
-
-
Save vtml/cc6d010440ac2795e0486a1081b4ec3e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
param( | |
[string] $LastGitCommitId, | |
[string] $AccessToken, | |
[string] $AzureDevOpsAccountName, | |
[string] $TeamProjectId, | |
[string] $ReleaseDefinitionId | |
) | |
if ([string]::IsNullOrEmpty($LastGitCommitId)) | |
{ | |
$hdrs = @{} | |
$hdrs.Add("Authorization","Bearer $AccessToken") | |
try | |
{ | |
$LatestSuccessfulRelease = Invoke-RestMethod -Method Get -Uri "https://$AzureDevOpsAccountName.vsrm.visualstudio.com/$TeamProjectId/_apis/release/releases?definitionId=$ReleaseDefinitionId&resultFilter=succeeded&`$top=1" -ContentType 'application/json' -Headers $hdrs | |
if ($LatestSuccessfulRelease.count -eq 1) | |
{ | |
$ReleaseDetailUrl = $LatestSuccessfulRelease.value[0].url | |
try | |
{ | |
$ReleaseArtifactDetail = Invoke-RestMethod -Method Get -Uri "$ReleaseDetailUrl" -ContentType 'application/json' -Headers $hdrs | |
if ($ReleaseArtifactDetail.PSobject.Properties.name -notcontains "innerException") | |
{ | |
$artifacts = $ReleaseArtifactDetail.artifacts | where {$_.definitionReference.project.id -eq $TeamProjectId} | |
if ($artifacts -ne $null) | |
{ | |
$GitCommitId = $artifacts[0].definitionReference.pullRequestMergeCommitId.id | |
Write-Host "##vso[task.setvariable variable=LastGitCommitId;]$GitCommitId" | |
} | |
} | |
else | |
{ | |
Write-Host "##vso[task.complete result=Failed;]Error in getting Release Details" | |
} | |
} | |
catch | |
{ | |
Write-Host "##vso[task.complete result=Failed;]Error in getting Release Details" | |
} | |
} | |
else | |
{ | |
Write-Host "##vso[task.complete result=Failed;]Error in getting the latest successful release." | |
} | |
} | |
catch | |
{ | |
Write-Host "##vso[task.complete result=Failed;]Error in getting the latest successful release." | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi Vincent,
Can you please help with how to use this script in VSTS?