javajunitpactcontractpact-broker

Correct basic Pact CICD workflow for new contract


I have a consumer CI which fails on merge request to main if verification test fails in provider's main branch.

I also have a provider CI which will fail if the verification tests against the main branch consumer contract fail.

What should be the correct process if no contract has been published from consumer's main branch and there are no provider tests on provider's main branch (i.e. new contract is being introduced)?

Should I set @IgnoreNoPactsToVerify and then merge the provider to main first, and then the consumer? Because without @IgnoreNoPactsToVerify by default the provider tests will fail (saying no contracts to have been found, which makes sense since I am matching only the latest main version of the consumer, and there is either no contract at all published yet, or just the one from a non-main branch made previously), so that tells me maybe this is not the correct setup?

Both consumer and provider are java applications and I am using pact broker. I am not using environments or record deployments yet, only branches and tags (when publishing contracts/verification results).

Or maybe the correct thing to do is add @IgnoreNoPactsToVerify until consumer is merged to main, and after that do another merge on provider's side just to remove @IgnoreNoPactsToVerify?


Solution

  • Pact is consumer-driven, so in the intended setup, the consumer is changed before the provider so that a pact is available once the provider verification runs.

    In your setup, that could mean to disable provider verification in the consumer pipeline for now and push first contract test to main and publish first pact. (This could be a simple skeleton, hidden behind a feature toggle or otherwise not used in production).

    See the CI/CD Setup Guide for multiple iterations from "no pacts" towards "pacts with branches and PR validation".

    But you can also use @IgnoreNoPactsToVerify temporarily on the provider. There's also a pact.verifier.ignoreNoConsumers system property with similar effect, see Pact JVM System Properties.