Skip to main content

Start a deploy when a pull request merges

When a task's pull request merges, a webhook can tell your deploy system straight away, so the change goes out without anyone pressing a button. A small receiver of yours gets the event, checks it came from Jaah, and starts the deploy for that project and commit. How endpoints, events and deliveries work is in How webhooks work.

You need to be an Owner or Admin of your organization, on a plan that includes webhooks, and a receiver at a public https:// address that can start a deploy.

  1. Open Settings, select Integrations, then Webhooks, and select New webhook.

  2. Enter a Name that says where the events go, such as Deploy on merge, and the URL of your receiver.

  3. Under Events, tick Pull request merged and leave everything else clear, so the receiver only hears about merges.

    The Events section of a new webhook, with Pull request merged ticked

  4. Under Projects, clear All projects and tick only the projects this receiver deploys. With All projects kept, a project added later would start sending merges to it too.

  5. Select Create, and copy the signing secret into your receiver's configuration. Jaah shows it only once.

  6. Have your receiver, for each delivery:

    • check the signature first, as in Verify the signature, and refuse a delivery that fails it;
    • skip a delivery it has already handled, since a delivery can arrive more than once;
    • read the project's name and the pull request's merge_sha from the body, shown in What a delivery looks like, and start the deploy of that commit;
    • answer with a 2xx status within 10 seconds, and run the deploy after it answers. A deploy takes longer than that, and a slow answer counts as a failed attempt, which Jaah sends again.
  7. Open the endpoint and select Send test. Its Deliveries tab shows the ping as Delivered once your receiver answers. A ping names no project or pull request, so your receiver should answer it without deploying.

  8. After the next merge, check the Deliveries tab. If a delivery failed, fix the receiver and select Redeliver on its row; Fix a failing webhook shows how to read why it failed.

Only pull requests that a task opened send this event: one your team opened by hand sends nothing, so keep your usual deploy for those. Deliveries can also arrive out of order: when two merges land close together, use each body's created_at so an older commit never replaces a newer one.