How to generate a synthetic webhook for Bitbucket server with curl?

Article ID:360056666452
1 minute readKnowledge base

Issue

Webhook troubleshooting is difficult when you don’t know if the issue is with the webhook (on the SCM side) or an issue with Jenkins. Use curl to generate a synthetic (fake) webhook to validate webhook reception on Jenkins.

Resolution

Bitbucket Server (from Post-webhook addon)

  • Simple push webhook payload

{
  "actor": {
    "username": "myusername",
    "displayName": "My User Name",
    "emailAddress": "myuser@cloudbees.com"
  },
  "repository": {
    "scmId": "git",
    "project": {
      "key": "WEB",
      "name": "webhook"
    },
    "slug": "simple-java-maven-app",
    "links": {
      "self": [
        {
          "href": "https://localhost:7990/projects/WEB/repos/simple-java-maven-app/browse"
        }
      ]
    },
    "ownerName": "WEB",
    "public": false,
    "fullName": "WEB/simple-java-maven-app",
    "owner": {
      "username": "WEB",
      "displayName": "WEB",
      "emailAddress": null
    }
  },
  "push": {
    "changes": [
      {
        "created": false,
        "closed": false,
        "new": {
          "type": "branch",
          "name": "main",
          "target": {
            "type": "commit",
            "hash": "b7c6fa5e437beb9dba60993f326ea26c4be6eca8"
          }
        },
        "old": {
          "type": "branch",
          "name": "main",
          "target": {
            "type": "commit",
            "hash": "f690661139936373bb0c4a1f2534cc5cfceb0707"
          }
        }
      }
    ]
  }
}
The commit hashes don’t matter because we are only validating a push event with Jenkins logs
  1. Copy json above and replace fields and save it as file.json

  2. Run curl

curl -X POST -H "X-Event-Key: repo:push" -H "X-Bitbucket-Type: server" -H "Content-Type: application/json; charset=UTF-8" https://JENKINS_URL/bitbucket-hook/ -d @file.json

Expected Output

2020-12-20 00:42:22.943+0000 [id=1198]	INFO	c.c.j.p.BitbucketPayloadProcessor#processPayload: Processing new Cloud Webhooks payload
2020-12-20 00:42:22.944+0000 [id=1198]	INFO	c.c.j.plugins.BitbucketJobProbe#triggerMatchingJobs: Triggering BitBucket job free
This article is part of our Knowledge Base and is provided for guidance-based purposes only. The solutions or workarounds described here are not officially supported by CloudBees and may not be applicable in all environments. Use at your own discretion, and test changes in a safe environment before applying them to production systems.