Forked from IlyaFinkelshteyn/StartBuildWaitForLogEntries.ps1
Created
July 20, 2018 04:04
-
-
Save Wasapl/289365bb33e359b6e66be681d7c4311d 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
$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