Hi All! I have a question regarding provider verif...
# general
t
Hi All! I have a question regarding provider verification. I would like to achieve the following: • Webhook triggers the provider verification when a contract was changed and published from the consumer merge request. The provider should take the contract published from the consumer’s merge request or the latest published contract. • When provider opens a merge request then the verification should happen for the contract which was published from the consumer’s main branch. I created a webhook in PactFlow and it triggers the verification anytime when the contract is changed/published. However, I can’t come up with the idea how to achieve the described scenarios above. I was thinking to provide a
--consumer-version-tags="main"
for provider verification job but then the first scenario won’t work, the provider will always take the contract with
main
tag which is assigned after merge to the main branch. Also, I can create two verification jobs for provider, one will be triggered by webhook only, another one will run when merge request is opened from provider. But it doesn’t look great. Do you have any ideas how I can achieve my desired result described above? Maybe I can play with tags somehow or pass something to my webhook? Please advice 🙂
I have the following webhook in PactFlow
and the job in gitLab for the verification
Copy code
verify contracts:
  stage: validate
  image:
    name: pactfoundation/pact-ref-verifier:latest
  script:
    - >-
      /usr/local/bin/pact_verifier_cli
      --hostname="app"
      --broker-url="$PACT_BROKER_BASE_URL"
      --token="$PACT_BROKER_TOKEN"
      --loglevel="info"
      --provider-branch="$CI_COMMIT_REF_SLUG"
      --provider-version="$CI_COMMIT_SHA"
      --provider-tags="$CI_COMMIT_REF_NAME"
      --consumer-version-tags="main"
      --provider-name="dummy-microservice-provider"
      --publish
  rules:
    - if: $CI_COMMIT_REF_NAME == $CI_DEFAULT_BRANCH && $CI_PIPELINE_SOURCE == "push"
    - if: $CI_MERGE_REQUEST_ID
    - if: $CI_PIPELINE_SOURCE == "trigger"
in other words, I’d like to take the
latest
published contract version when a webhook triggers the verification. And I’d like to take the contract published from
main
branch only in other cases.
m
Have you run through this workshop? https://docs.pactflow.io/docs/workshops/ci-cd
For (1), the webhook that fi res passes the contract that requires verification and triggers the build job
For (2) you should use the appropriate selectors that verifies the main branch
t
No, I didn’t went through the workshop. I’ll have a look. What do you mean saying “the appropriate selectors”? Like
--consumer-version-tags
?
ok, I had a look. And I changed my webhook and tried to use
--consumer-version-selectors="{\"mainBranch\": true}"
. 1. I provided the link to the latest contract. See screenshot. It works just fine and the latest published contract is taken until I provided selectors
2. I added selectors such as
--consumer-version-selectors="{\"mainBranch\": true}"
for my gitLab verification job. But now contracts posted from the main branch are taken only by webhook despite the fact that I specifically provided the url to the latest published contract in webhook.
Do you have any thoughts how I can handle it? Probably I need to say that I trigger the same gitLab verification job with webhook too, so have only one verification job
my webhook
I checked your repo https://github.com/pactflow/example-provider/blob/master/.github/workflows/contract_requiring_verification_published.yml Do I understand correctly that you created a separate job for webhook? It looks like I need to create one more job too specifically for webhook
y
yes, you should have two provider verification tasks, one for provider changes (which uses consumer version selectors) and one for webhook triggered builds by PACT_URL, these if you are using branchs/recording deployments rather than tags, will also provide a commit sha, so the webhook based verifications will take place against the latest on your configured main branch, and any released or deployed versions
👍 1
t
Thank you! I implemented two jobs and now it works as I wanted.
y
superb, top work @Tatiana
🙌 2