Search code examples
appveyor

Trigger an Appveyor build on particular commit


What I require is a command that start a build of a certain commit on Appveyor with particular environment variables. From the guides, there is:

  • From the build worker API: Start-AppveyorBuild which allows you to pass in environment variables but only lets you specify the branch, not the commit.
  • From the REST API: POST /api/builds which allows you to choose the commit hash, but can't set any environment variables for the ensuing build.

What is available that allows me to do both? I am fine to use either the build worker API or the REST API (although REST is preferable so then I can run it anywhere).

Broader context is I want a build to kick off a separate build that will run a deployment script of the same commit (same branch not good enough - branch may have been updated). They need to be separate builds due to the fact that both the first and second build together take too long for Appveyor's 60 minute time limit. The environment variables are to "configure" the build so that it deploys rather than does the other stuff.


Solution

  • Check this sample (and write to team at appveyor.com if you need us to increase timeout to 90 minutes)

    $token = '<API_Token>'
    
    $headers = @{
      "Authorization" = "Bearer $token"
      "Content-type" = "application/json"
    }
    
    $body = @{
        accountName="<Your_account>"
        projectSlug="<Your_project_slug>"
        branch="<Your_branch>"
        commitId="<Your_commit_id>"
    }
    $body = $body | ConvertTo-Json
    
    Invoke-RestMethod -Uri 'https://ci.appveyor.com/api/builds' -Headers $headers  -Body $body -Method POST