Created
May 2, 2019 17:59
-
-
Save IlyaFinkelshteyn/b978fd99a3711bc50eb76e3fbe658f11 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
# $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