Skip to main content

CI/CD Setup Guide

Or "The steps for reaching Pact Nirvana"

This is a technical guide for developers and testers who want to use Pact to implement consumer driven contract testing as part of your ongoing CI/CD workflow.

By the end of the guide, you will understand how to create a release pipeline that allows you to independently deploy any application with the confidence that it will work correctly with the other applications in its environment - without having to run a suite of end to end tests.

This guide focuses on the scenario where the consumer and provider are both being deployed to an environment rather than released to customers (e.g. a mobile app). That workflow is slightly different, and that guidance will be coming soon.

tip

For a complete hands-on workshop implementing the steps in this guide with GitHub, see: https://docs.pactflow.io/docs/workshops/ci-cd

How to use this document​

Each integration is different. Each organisation has different history and culture, and each team may have different processes for development, testing, and deployment. Each of these differences affect the best choices for Pact workflow.

However, there are many similarities in the steps necessary on the journey to a full-featured and effective Pact setup ("Pact Nirvana"). This document describes those steps.

Feel free to pick and choose the steps that apply best to your team. You may implement only the first few steps described below, and just use Pact as a precursor to your standard integration tests; or you may throw away your integration tests altogether and reach "Pact Nirvana".

This guide doesn't go into the details of how to write and run consumer tests or provider verification tests. Here we are laying out a high-level strategy for how you can get Pact set up and operational. Each of the levels below gets you a step towards having a fully automated process of verifying contracts as part of CI/CD with no need for an integration environment.

As Pact has been implemented in many different languages, this document will outline the theory for each step. You will need to consult the documentation of your chosen language to learn the relevant syntax for each task. See the implementation guides section for more information.

What are the steps for reaching Pact Nirvana?​

  1. Get Prepared - learn about pact
  2. Talk: get team alignment
  3. Bronze level: get a single test working manually
  4. Silver level: manually integrate with Pact Broker
  5. Gold level - integrate with your PR pipelines
  6. Platinum level: Add can-i-deploy with branch tag to PR pipelines
  7. Diamond level - Add Pact to your deploy pipelines
  8. Honors Course - To come in future...
    1. Add provider state
    2. Working with Feature Flags

Click below to expand and see each a diagram representing each level

Bronze diagram
write
read
Consumer Test
Pact File
Provider Verification by Local File
Silver diagram
publish
retrieve pact by url
Consumer Test
Pact Broker
Provider Verification by URL
Gold diagram
ConsumerBrokerProviderPR validation pipelineCommit/main pipelinePR validation pipelinepublish pact with branch [feat 123]publish pact with branch [main]verify against consumer's main branch and deployed versionspublish results, including provider version + branchConsumerBrokerProvider
Diamond diagram
ConsumerBrokerVerifierPR validation pipelinealt[: verification passed][: verification failed]alt[: verification passed][: verification failed]alt[: pact has changed, verification does not exist][: no change to pact, verification exists]publish pact with branch [feat abc]{webhook} run verification for pact version 123 [feat abc]can-i-deploy --to-environment devwait for results...pull provider from main branchget pact version 123verify against pactYesNOcan-i-deploy --to-environment devYesNOConsumerBrokerVerifier
Diamond with release branch diagram
ProviderBrokerPR validation pipelineMain branch commit pipelineRelease branch pipelineverify pacts with [mainBranch] and [deployedOrReleased] selectorspublish results, tag with provider branch [feat abc]can-i-deploy --to-environment [staging]verify pacts with [mainBranch] and [deployedOrReleased] selectorspublish results, tag with provider branch [main]can-i-deploy --to-environment [staging]deploy to [staging]pact-broker record-deployment --environment [staging]can-i-deploy --to-environment [preprod]can-i-deploy --to-environment [prod]cut release branchdeploy to [preprod]run [preprod] testscan-i-deploy --to-environment [prod]deploy to [prod]pact-broker record-deployment --environment [prod]ProviderBroker
Is this page useful?