Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
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 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-deployis 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 test job- runs the unit tests and the pact tests, and publishes the verification results back to the broker.
contract_content_changedwebhook - 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_publishedwebhook - triggers
Consumer pact check job. This webhook will be triggered every time a verification is published. The
can-i-deploytool 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.
- Debugging webhooks
- Webhook API documentation - note that there is not yet a UI for creating webhooks. If you're interested in creating one, contact us on the Pact Broker gitter channel.
can-i-deploy documentation - Documentation for the Pact Broker
can-i-deployCLI, which allows you to retrieve the verification results and determine whether your application is safe to deploy.
- Webhook template library - a library of useful webhook templates