Skip to content

Instantly share code, notes, and snippets.

@EamonKeane
Last active February 1, 2018 18:37
Show Gist options
  • Save EamonKeane/4bc74fab21f49383aa9d2bdd9d243a6b to your computer and use it in GitHub Desktop.
Save EamonKeane/4bc74fab21f49383aa9d2bdd9d243a6b to your computer and use it in GitHub Desktop.
Create a webhook for a github repository.
#!/usr/bin/env bash
# this creates a github webhook that gets all events to a repository, useful with Jenkins Blue Ocean
service_url="https://my_url"
service_port="my_port"
organisation=""
repository=""
git_url="https://api.github.com/repos/${organisation}/${repository}/hooks"
auth_token="" # needs to have admin permissions for the repository
generate_post_data()
{
cat <<EOF
{
"name": "web",
"active": true,
"events": ["*"],
"config": {
"url": "${service_url}:${service_port}/github-webhook/",
"content_type": "application/x-www-form-urlencoded"
}
}
EOF
}
curl -H "Content-Type: application/x-www-form-urlencoded" \
-H "Authorization: token ${auth_token}" \
--data "$(generate_post_data)" \
${git_url}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment