Starter Project

Updated 2 years ago by Admin

Create a Webhook Receiver

The goal of this tutorial is to build a custom webhook receiver using our starter project template as the base. A webhook receiver is a small http server that receives and processes webhooks.

This tutorial assumes you have a working knowledge of the Go programming language. You will also need to install boilr, a scaffolding system used to generate new code projects from templates.

Step 1: Create the Project

Drone provides scaffolding for creating a new webhook receiver from a project template. We will bootstrap our project using this template.

  1. Install the webhook template.
    $ boilr template download drone/boilr-webhook drone-webhook
  2. Create a new webhook project.
    $ boilr template use drone-webhook my-webhook-receiver

Step 2: Customize the Code

The generated project creates a simple server capable of receiving, authenticating and parsing requests. You only need to modify the plugin.Deliver function to include your custom processing logic.

1  package plugin
3 import (
4 "context"
6 ""
7 )
9 // New returns a new webhook extension.
10 func New() webhook.Plugin {
11 return &plugin{}
12 }
14 type plugin struct {
15 }
17 func (p *plugin) Deliver(ctx context.Context, req *webhook.Request) error {
18 // insert your custom logic here
return nil
19 }

Step 3: Build Your Docker Image

The generated project includes a Dockefile that you can use to build and publish images. You will need to update the Dockerfile entrypoint.

  1. Build your binary file:
    $ GOOS=linux CGO_ENABLED=0 go build
  2. Build and publish your Docker image:
    $ docker build -t my-webhook-receiver .
    $ docker push my-webhook-receiver

Step 4: Start the Webhook Receiver

  1. Create a shared secret used to sign the http request:
    $ openssl rand -hex 16
  2. Start the webhook receiver.
    $ docker run \
    -p 3000:3000 \
    -e DRONE_SECRET=bea26a2221fd8090ea38720fc445eca6 \

Step 5: Enable Webhooks

Once the webhook receiver is running you will need to provide your Drone server with the webhook endpoint and secret:


How did we do?