Hello everyone. I am currently working on a POC to...
# pact-broker
a
Hello everyone. I am currently working on a POC to have the contract testing execution and publication run in one pipeline, and the verification in another separate pipeline. To trigger the verification pipeline, I use a webhook from the pact-broker:
contract_content_changed
. In the webhook's body, I send the necessary information to initiate the provider build. See the webhook in the đź§µ. Is there a way to obtain not only the
consumerVersionBranch
but also the consumer's base branch? Something like:
"consumerBaseBranch": "${pactbroker.consumerVersionBaseBranch}"
. Any ideas? Thanks in advance.
Copy code
{
    "description": "Trigger provider verification when contract content changes",
    "events": [
        {
            "name": "contract_content_changed"
        }
    ],
    "request": {
        "method": "POST",
        "url": "<https://jenkins.something.org>",
        "headers": {
            "content-type": "application/json"
        },
        "body": {
            "pactUrl": "${pactbroker.pactUrl}",
            "consumerName": "${pactbroker.consumerName}",
            "consumerVersion": "${pactbroker.consumerVersionNumber}",
            "consumerBranch": "${pactbroker.consumerVersionBranch}",
            "consumerTags": "${pactbroker.consumerVersionTags}",
            "providerName": "${pactbroker.providerName}",
            "providerVersion": "${pactbroker.providerVersionNumber}",
            "providerBranch": "${pactbroker.providerVersionBranch}",
            "providerTags": "${pactbroker.providerVersionTags}",
        }
    }
}
m
what do you mean by base branch?
the main branch such as
main
or
master
?
what are you hoping to achieve with that?
You should also be using the later version of that event, which is an improved version of it: https://docs.pact.io/pact_broker/webhooks#the-contract-requiring-verification-published-event
a
Let’s say my default branch is
develop
. Suppose a create a feature branch from there
feat-1
. So the base branch of
feat-1
is
develop
. But sometimes the base branch is a different branch than the default branch and we verify the contract there. In the Jenkins pipeline that publish the contract I can obtain both the feature branch and the base branch. When publishing the contract I can send the name of the feature branch and access it in the webhook. But I also need the base branch and I don't know how to send it. Can the
--branch
flag accept a list of branches? To publish the contracts we do something similar to this in the consumer pipeline:
Copy code
def branchName = env.BRANCH_NAME
def baseBranchName = env.CHANGE_TARGET

"""
docker run --rm \
pactfoundation/pact-cli:latest \
publish \
pacts \
--consumer-app-version ${gitCommit} \
--broker-base-url=${brokerUrl} \
--tag=${tag} \
--branch=${branchName} \
"""
The current implementation is little bit old and uses tags instead of branches, we're updating it step by step. That's why I'm not using the improved version of the webhook yet. That will be done in the future when we migrate from tags to branches.
nice 7771 1
m
But I also need the base branch and I don’t know how to send it. Can the
--branch
flag accept a list of branches?
No, we don’t support that sorry. I don’t think we ought to build something like that either. What do you need the base branch for?