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

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.

Environment

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": "http://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": "master",
          "target": {
            "type": "commit",
            "hash": "b7c6fa5e437beb9dba60993f326ea26c4be6eca8"
          }
        },
        "old": {
          "type": "branch",
          "name": "master",
          "target": {
            "type": "commit",
            "hash": "f690661139936373bb0c4a1f2534cc5cfceb0707"
          }
        }
      }
    ]
  }
}

Note: 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" http://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

Have more questions?

0 Comments

Please sign in to leave a comment.