Webhooks

Beth Skurrie edited this page May 5, 2018 · 19 revisions

Webhooks allow you to trigger an HTTP request when a pact is changed, or a verification is published. The most common use case for webhooks is to trigger a provider build every time a pact changes, and to trigger a consumer build every time a verification is published.

Webhooks can be used in conjunction with the can-i-deploy tool (a CLI that allows you to easily check the verification status of your pacts), to allow you to fully automate the CI/CD process for all the applications that use the Pact Broker, ensuring both sides of the contract are fulfilled before deploying.

Example CI/CD and webhook configuration

Note that if the pact content has not changed, it is "pre verified", and the provider verification portion of this diagram can be skipped.

What to do if your Pact Broker webhooks can't contact your CI because it is in a private network

If your consumer and provider builds are both within the same private network, you can achieve a similar result by having your builds trigger each other directly. You'll just end up with a provider build for every consumer build, rather than a provider build for every pact change.

Consumer CI

  • Consumer test job - runs unit tests, runs pact tests, publishes pact. Triggers Consumer pact check job
  • Consumer pact check job - this is the point where you decide if you can deploy the consumer straight away, or if you need to wait for the pact to be verified. It checks the status of the pacts using can-i-deploy. If can-i-deploy is successful, this job triggers Consumer deploy. If it is unsuccessful, it should fail the job to provide visibility of the status of your pacts in the build pipeline. Having this as a separate job rather than bundling it in with the test or deploy jobs means that the reason for a "failure" is obvious at a glance.
  • Consumer deploy job - deploys consumer

Provider CI

  • Provider test job - runs the unit tests and the pact tests, and publishes the verification results back to the broker.

Pact Broker

  • contract_content_changed webhook - triggers Provider test job. Note that this webhook will only be triggered if the content of the pact has changed. If it hasn't changed, then the new publication of the pact will inherit the verification from the previous publication and be "pre-verified" (or "pre-failed").
  • provider_verification_published webhook - triggers Consumer pact check job. This webhook will be triggered every time a verification is published. The can-i-deploy tool will need to be used in conjunction with a query to the state of your own infrastructure to let you decide whether or not you need to deploy the consumer. ie. the provider may verify the same version of the pact multiple times, invoking the webhook each time, but you only want to deploy a certain version of your consumer once.

Related resources

You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.