Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IlyaFinkelshteyn/b978fd99a3711bc50eb76e3fbe658f11 to your computer and use it in GitHub Desktop.
Save IlyaFinkelshteyn/b978fd99a3711bc50eb76e3fbe658f11 to your computer and use it in GitHub Desktop.
# $env:API_KEY should be defined as a secure variable
$headers = @{
"Authorization" = "$env:API_KEY"
"Content-type" = "application/json"
}
$apiURL = "https://ci.appveyor.com/api/projects/$env:APPVEYOR_ACCOUNT_NAME/$env:APPVEYOR_PROJECT_SLUG"
$history = Invoke-RestMethod -Uri "$apiURL/history?recordsNumber=5" -Headers $headers -Method Get
if ($history.builds.Count -eq 5)
{
$previousBuild = $history.builds | ? {($_.commitId -eq $env:APPVEYOR_REPO_COMMIT) -and ($_.buildId -ne $env:APPVEYOR_BUILD_ID)} | Sort-Object -Property created -Descending | Select-Object -First 1
if ($previousBuild) {
if ($previousBuild.status -eq "success") {
Write-Host "Commit $env:APPVEYOR_REPO_COMMIT was already built with success"
Exit-AppveyorBuild
}
elseif ($previousBuild.status -eq "failed") {
Throw "Commit $env:APPVEYOR_REPO_COMMIT was already already built with failure"
}
else {
Write-Host "Commit $env:APPVEYOR_REPO_COMMIT was already built, but without either success or failure, continuing..."
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment