Search code examples
pact-broker

how to create a valid webhook which can be triggered by Provider_verification_published event in pact broker?


to automate contract testing by leveraging pact broker webhooks, I created customized contract_content_changed event with a jenkins job. but when I was trying to add webhook for customer pipeline which is triggered by verification result publishing, it failed several times.

{"consumer": {
    "name": "Consumer Service"
  },
  "provider": {
    "name": "Provider Service"
  },
  "events": [
    {
      "name": "provider_verification_published"
    }
  ],
  "request": {
    "method": "POST",
    "url": "http://jenkinsserver/jobforconsumerdeployment",
    "headers": {
      "Accept": "application/json"
    },
   "body": {"VerificationResultURL","${pactbroker.verificationResultUrl}"
    }
}

after removing body element, it created successfully. by passing body to customer job, it could parse fail/pass and decide whether deployment should go or not go.

if body is not allowed, how consumer pipeline to get the result and continue next step (or stop deployment)?

I am referring to Pact Broker Webhooks.


Solution

    1. Configure Jenkins job to "Trigger builds remotely" from Build Triggers section
    2. Generate Jenkins-Crumb by the following link Steps to create Jenkins-Crumb
    3. Following post request in Pact-Broker is working fine for me on my local jenkins setup (need to check jenkin permissions to enable web-hook execution) { "events": [{ "name": "provider_verification_published" }], "request": { "method": "GET", "url": "http://username:password@jenkins_url/job/jenkin_consumer/build?token=abc", "user" : "username:password", "headers": { "Jenkins-Crumb": "c787ce16220300f5ef8287a4474d9acxd" } } }

    if body is not allowed, how consumer pipeline to get the result and continue next step (or stop deployment)?

    Yes, body is not allowed in case of 'provider_verification_published' event. So to confirm the verification results, we need to use "can-i-deploy" cli to deply or stop the deployment can-i-deploy. More information provided on Pact Broker Webhooks