This guide provides a brief tutorial for creating a webhook plugin, using the Go programming language, to trigger http requests during the build pipeline. The below example demonstrates how we might configure a webhook plugin in the Yaml file:
|
|
Create a Go program that makes an http request using the Yaml configuration parameters, which are passed to the program as environment variables in uppercase, prefixed with PLUGIN_. Here is more information on plugin inputs.
|
|
Compile your binary on the host machine for the target platform. Compiling on the host machine and adding the binary to the image is considered a best practice because it reduces the overall image size.
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -o webhook
Create a Dockerfile that adds your compiled binary to the image, and configures the image to run your binary as the main entrypoint.
|
|
Build and publish your plugin to the Docker registry. Once published your plugin can be shared with the broader Drone community.
$ docker build -t acme/webhook .
$ docker push acme/webhook
Execute your plugin locally from the command line to verify it is working:
$ docker run --rm \
-e PLUGIN_METHOD=post \
-e PLUGIN_URL=http://hook.acme.com \
-e PLUGIN_BODY=hello \
acme/webhook
Starter Project
If you are interested in creating plugin we recommend using our starter project as a base to jumpstart development.