2

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.

Yunxing
  • 23
  • 3

1 Answers1

0
  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

  • Shekhar, thanks for the detailed context. I am able to trigger consumer job by 'provider_verification_published'. But, as you mentioned, the cli 'can-i-deloy' can tell whether it pass or not with specified tag. but I am using python, the cli is ruby based. is there a Wiki or introduction which can show me the logic and APIs(pact broker) behind the command(can-i-deloy)? – Yunxing Nov 15 '18 at 06:40
  • Hi Yun, once the verification result (a result generated after provider verification step) gets published to pact broker (check option how to publish result to pact broker in a library which you are using to verify contract) a cli 'can-i-deploy' comes in to role. – Shekhar Patil Nov 16 '18 at 08:14
  • As the cli works along with pact broker it will not matter which technology is being used to implement consumer or provider.The cli confirms the consumer and provider version are compatible with each other and are safe to deploy. [link] (http://blog.pact.io/tag/can-i-deploy/ ) – Shekhar Patil Nov 16 '18 at 08:31
  • thanks for explanation, I will try and update here later – Yunxing Nov 22 '18 at 13:59
  • tried can-i-deploy, it works well. I am considering to integrate my pipeline with webhook. then, I can get the whole build/verify process automatically. the possible solution is split provider_verification_published into provider_verification_success_published and provider_verification_failure_published. in that way, pipeline can get a clear notification whether deployment can go or no go. Please share your thoughts. – Yunxing Dec 04 '18 at 07:35
  • Have a look at the [Build Pipeline using Pact Broker and Jenkins](https://medium.com/kreuzwerker-gmbh/integrating-contract-tests-into-build-pipelines-with-pact-broker-and-jenkins-674d21c3f44b), this will be a good pointer – Shekhar Patil Jan 07 '19 at 05:52