Webhooks are an incredibly useful way to tie together disparate network parts, WHEN something happens in one place, it sends a POST HTTP request to another place.
Create the Bitbucket Webhook and Setup a Server to Receive the Webhook
- Log in to the Bitbucket WebUI
- Choose the repository
- Choose to administer the repository (gear symbol) -> Hooks (left menu) , or simply https://bitbucket.org/username/reponame/admin/hooks
- Select Hook Type (dropdown) , POST , Add Hook (Button)
- Enter your target URL, SAVE
- Setup a webserver (easiest might be Bamboo or Jenkins) somewhere
- Ensure there is a URL that accepts POST requests
- Ensure that when the POST is received it runs the pelican content generation commands to make the new output
- Ensure new output is visible
You may notice any existing POST webhooks, i.e. a HipChat notification add-on, listed: https://hipchat-bitbucket.herokuapp.com/commit?client_id=f955ddb5
Flask and Bash source code to publish a pelican static web site
This custom solution requires running that flask app manually, i.e. python mypublish.py It also requires having two repositories, one for the pelican source content, the other repo (i.e. a bitbucket static web site) will only contain the output (.html files)
vi mypublish.py
from flask import Flask
import os
from subprocess import Popen, PIPE
app = Flask(__name__)
@app.route('/someuniquekeyhere', methods=['GET', 'POST'])
def mypublish():
try:
output = Popen(["./mypublish.sh"], stdout=PIPE).communicate()[0]
except Exception as error:
return str(error)
return output
if __name__ == '__main__':
app.run('0.0.0.0', 8443, use_reloader=True)
vi mypublish.sh
#!/bin/bash
git pull
GITMESSAGE=$(git log -n 1)
OUTPUT="../outputreponame.bitbucket.io"
./clean-output.sh "../sourcereponame.bitbucket.io" # removes all of the old content
echo "$GITMESSAGE"
pelican content
cp -a ./output/* $OUTPUT
rm -rf ./output
rm -rf ./cache
rm -f *.pyc
cd "$OUTPUT"
git add --all ./content
git commit -m "source $GITMESSAGE"
git push
vi clean-output.sh
#!/bin/bash
rm -rf ./output
rm -rf ./cache
rm -f *.pyc
for ITEM in $SOURCE/*
do
if [ -d "$ITEM" ]; then
rm -rf "$ITEM"
else
rm -f "$ITEM"
fi
done