Cancelling builds

liam.kennedy's Avatar

liam.kennedy

07 Apr, 2017 03:57 PM

Hey.

We are currently building Debug, QA and Release configurations on most projects. Is there a way to cancel QA and Release builds if Debug build fails?

Thanks

Liam

  1. Support Staff 1 Posted by Ilya Finkelshte... on 07 Apr, 2017 05:15 PM

    Ilya Finkelshteyn's Avatar

    Hi Liam,

    Something like this should work. Build will cancel itself if job with Debug configuration fails. Please ensure Debug is first in configurations list. Though we do not guarantee order of jobs in build matrix, first one in list has better chance to be executed first.This is especially important if you do not have a lot of concurrent jobs in your plan.

    version: 1.10.{build}
    configuration:
    - Debug
    - QA
    - Release
    environment:
      API_TOKEN: egp7tq82pys3pr6ymy0u
    build:
      verbosity: minimal
    on_failure:
    - ps: >-
        IF($env:CONFIGURATION -eq "Debug") {
            $headers = @{
                "Authorization" = "Bearer $env:API_TOKEN"
                "Content-type" = "application/json"
            }
            Invoke-RestMethod -Uri "https://ci.appveyor.com/api/builds/$env:APPVEYOR_ACCOUNT_NAME/$env:APPVEYOR_PROJECT_SLUG/$env:APPVEYOR_BUILD_VERSION " -Headers $headers  -Method DELETE
        }
    

    Ilya.

  2. 2 Posted by liam.kennedy on 19 Apr, 2017 11:12 AM

    liam.kennedy's Avatar

    Thanks Ilya

  3. 3 Posted by liam.kennedy on 27 Apr, 2017 10:49 AM

    liam.kennedy's Avatar

    Hi

     
    I used that on_failure ps script but it doesn’t produce exactly the behaviour we want.

     
    It says ‘Build has been cancelled by user’ which is misleading – QA and Release builds were cancelled because debug build failed, therefore it should appear as a failed build.

     
    Is there a way to fail the build rather than cancel it if debug build fails? It needs to be red in AppVeyor and send out a build fail email notification.

     
    Liam

  4. Support Staff 4 Posted by Ilya Finkelshte... on 27 Apr, 2017 09:07 PM

    Ilya Finkelshteyn's Avatar

    You can do something like this at init stage.
    Note that this will work as expected while you have 1 concurrent job. If you upgrade your plan with more jobs, other builds might start before Debug finished. To make it work then you will be needed to set max jobs to 1 for this project.

    if ($env:Configuration -ne "Debug"){
        Write-Host "Checking for Debug build status..."
    
        $headers = @{
          "Authorization" = "Bearer $env:API_TOKEN"
          "Content-type" = "application/json"
        }
        
        $currentBuild=Invoke-RestMethod -Uri "https://ci.appveyor.com/api/projects/$env:APPVEYOR_ACCOUNT_NAME/$env:APPVEYOR_PROJECT_SLUG/build/$env:APPVEYOR_BUILD_VERSION " -Headers $headers  -Method Get
    
        if (($currentBuild.build.jobs | Where-Object {$_.name -eq "Configuration: Debug"}).status -eq "failed") {throw "Debug failed, no reason to continue"}
    }
    else {
        Write-Host "Skipping check for Debug build status as this build job is Debug itself"}
    

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:

»

Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac