Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Wasapl/289365bb33e359b6e66be681d7c4311d to your computer and use it in GitHub Desktop.
Save Wasapl/289365bb33e359b6e66be681d7c4311d to your computer and use it in GitHub Desktop.
$token="<Your_api_token>"
$accountName="<Your_account>"
$projectSlug="<Your_project_slug>"
$toFind = @("foo", "bar")
$headers = @{
"Authorization" = "Bearer $token"
"Content-type" = "application/json"
}
$body = @{
accountName=$accountName
projectSlug=$projectSlug
}
$body = $body | ConvertTo-Json
$newBuild = Invoke-RestMethod -Uri 'https://ci.appveyor.com/api/builds' -Headers $headers -Body $body -Method POST
$jobId = (Invoke-RestMethod -Uri "https://ci.appveyor.com/api/projects/$accountName/$projectSlug/build/$($newBuild.version)" -Headers $headers -Method GET).build.jobs[0].jobId
$status = "running";
$found = $false
while(($status -eq "running") -and ($found -eq $false)) {
try {$log = Invoke-RestMethod -Uri "https://ci.appveyor.com/api/buildjobs/$jobId/log" -Headers $headers -Method GET} catch {}
if ($log) {
$found = $true
$toFind | % {if(!$log.Contains($_)) {$found = $false}}
$status = (Invoke-RestMethod -Uri "https://ci.appveyor.com/api/projects/$accountName/$projectSlug/build/$($newBuild.version)" -Headers $headers -Method GET).build.status
write-host "Status: $status"
write-host "Found: $found"
if ($found) { $toFind | % {$log.Split([Environment]::NewLine) | Select-String $_}}
}
sleep 1
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment