Webhooks template library
Please feel free add any that you think might be useful to others.
Github - publish commit status
Report the pact verification status back to the consumer project in Github.
{
"consumer": {
"name": "<consumer name>"
},
"events": [
{
"name": "contract_published"
},
{
"name": "provider_verification_published"
}
],
"request": {
"method": "POST",
"url": "https://api.github.com/repos/<organization>/<project>/statuses/${pactbroker.consumerVersionNumber}",
"headers": {
"Content-Type": "application/json"
},
"body": {
"state": "${pactbroker.githubVerificationStatus}",
"description": "Pact Verification Tests",
"context": "${pactbroker.providerName} ${pactbroker.providerVersionTags}",
"target_url": "${pactbroker.verificationResultUrl}"
},
"username": "USERNAME",
"password": "PASSWORD"
}
}
Slack - post notification
{
"events": [
{
"name": "contract_published"
},
{
"name": "provider_verification_published"
}
],
"request": {
"method": "POST",
"url": "https://hooks.slack.com/services/<webhook id>",
"headers": {
"Content-Type": "application/json"
},
"body": {
"channel": "#<your-channel-here>",
"username": "webhookbot",
"text": "New version of pact created for ${pactbroker.consumerName}/${pactbroker.providerName}: ${pactbroker.pactUrl}",
"icon_emoji": ":ghost:"
}
}
}
Travis - trigger build
{
"events": [{
"name": "contract_content_changed"
}],
"request": {
"method": "POST",
"url": "https://api.travis-ci.org/repo/<organization>%2F<project>/requests",
"headers": {
"Content-Type": "application/json",
"Accept": "application/json",
"Travis-API-Version": "3",
"Authorization": "token TOKEN"
},
"body": {
"request": {
"message": "Triggered by changed pact for ${pactbroker.consumerName} version ${pactbroker.consumerVersionNumber}",
"branch":"master",
"config": {
"env": {
"global": [
"PACT_URL=${pactbroker.pactUrl}"
]
}
}
}
}
}
}
Ref:
Bamboo - trigger build
{
"request": {
"method": "POST",
"url": "http://master.ci.my.domain:8085/rest/api/latest/queue/SOME-PROJECT?os_authType=basic?bamboo.variable.pact-url=${pactbroker.pactUrl}",
"username": "username",
"password": "password",
"headers": {
"Accept": "application/json"
}
}
}
Ref:
Azure DevOps - trigger build
{
"request": {
"method": "POST",
"url": "https://<instance>/<organization>/<project>/_apis/build/builds?api-version=6.0",
"headers": {
"Content-Type": "application/json",
"Accept": "application/json",
"Authorization": "<authorization>"
},
"body": {
"definition": {
"id": <build-definition-id>
},
"sourceBranch": "refs/heads/master"
}
}
}
Ref:
CircleCI - trigger workflow build
N.B - currently need to use a personal API token (ideally for a machine user)
{
"events": [
{
"name": "contract_content_changed"
}
],
"request": {
"method": "POST",
"url": "https://circleci.com/api/v1.1/project/<VCS>/<ORG>/<REPO>/build?circle-token=****",
"headers": {
"Content-Type": "application/json"
},
"body": {
"branch": "<BRANCH>"
}
}
}
Bitbucket - pipeline trigger build of a branch
If you use Bitbucket and have worked out how to pass parameters into the build, can you please submit a PR to update this example.
{
"events": [{
"name": "contract_content_changed"
}],
"request": {
"method": "POST",
"url": "https://api.bitbucket.org/2.0/repositories/{workspace}/{repo_slug}/pipelines/",
"headers": {
"Content-Type": "application/json"
},
"username": "username",
"password": "password",
"body": {
"target": {
"ref_type": "branch",
"type": "pipeline_ref_target",
"ref_name": "your_branch_name"
}
}
}
}
Ref:
Buildkite - trigger build
{
"events": [
{
"name": "contract_content_changed"
}
],
"request": {
"body": {
"branch": "master",
"commit": "HEAD",
"message": "Build all the things! :rocket:",
"env": {
"PACT_URL": "${pactbroker.pactUrl}"
}
},
"headers": {
"Authorization": "Bearer TOKEN",
"Content-Type": "application/json"
},
"method": "POST",
"url": "https://api.buildkite.com/v2/organizations/<ORG>/pipelines/<PIPELINE>/builds"
}
}
Ref:
GitLab - trigger build
{
"request": {
"method": "POST",
"url": "https://gitlab.com/api/v4/projects/:id/ref/:ref/trigger/pipeline?token=:token&variables[PACT_URL]=${pactbroker.pactUrl}",
"headers": {
"Accept": "application/json"
}
},
"events": [
{
"name": "contract_content_changed"
}
]
}
Ref:
TeamCity - trigger build
If you use TeamCity and know out how to pass parameters into the build, can you please submit a PR to update this example.
{
"events": [
{
"name": "contract_content_changed"
}
],
"request": {
"method": "POST",
"url": "https://teamcity.net/app/rest/buildQueue?",
"headers": {
"Content-Type": "application/xml",
"Authorization": "bearer token"
},
"body": "<build><buildType id='YourJobId'\/><\/build>",
"username": "username",
"password": "password"
}
}
Ref: