Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save IlyaFinkelshteyn/9b669f4c94e0b70195c2f8c0a62a340f to your computer and use it in GitHub Desktop.
Save IlyaFinkelshteyn/9b669f4c94e0b70195c2f8c0a62a340f to your computer and use it in GitHub Desktop.
$env:API_TOKEN="<your_api_key>" # use secure variable in case script runs from the build
$env:APPVEYOR_ACCOUNT_NAME="your_account_name" # no need to setup in case script runs from the build (default environment variable)
$env:APPVEYOR_PROJECT_SLUG="your_project_slug" # no need to setup in case script runs from the build (default environment variable)
$env:RECORDS_NUMBER=10 # build history depth to search
#!!! We assume that if build has artifacts, this file exist in artifacts list
$artifact_file_name = "db.zip"
$headers = @{
"Authorization" = "Bearer $env:API_TOKEN"
"Content-type" = "application/json"
}
$history = Invoke-RestMethod -Uri "https://ci.appveyor.com/api/projects/$env:APPVEYOR_ACCOUNT_NAME/$env:APPVEYOR_PROJECT_SLUG/history?recordsNumber=$env:RECORDS_NUMBER" -Headers $headers -Method Get
$result = $history.builds | Where-Object {$_.status -eq "success"} | Sort-Object -Property created -Descending | Select-Object -First $env:RECORDS_NUMBER
$result | % {
$build = Invoke-RestMethod -Uri "https://ci.appveyor.com/api/projects/$env:APPVEYOR_ACCOUNT_NAME/$env:APPVEYOR_PROJECT_SLUG/build/$($_.version)" -Headers $headers -Method Get
$found = $false
foreach ($j in $build.build.jobs) {
if($j.artifactsCount -ne 0) {
Write-Host "https://ci.appveyor.com/api/buildjobs/$($j.jobId)/artifacts/$artifact_file_name"
$found = $true
}
}
if($found) {break}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment