blog, projects, games and my thoughts

I started using Gitlab a while ago, and wanted to use the Webhook feature to automatically update the website I was working on when the master branch was updated.

I looked for an easy solution on the internet, but didn’t find anything that worked out of the box. Finally I came up with this code, that worked for me.

The following php file, can be added like http://domain.ch/webhooks/webhook.php?key=someKey to the Webhook section in Gitlab. The key can be anything. It just makes sure that if someone accidentally opens the webpage it won’t trigger an update. It also checks the IP of the client that connects. So the IP of the gitlab server has to be added. The script logs everything into a file: webhook.log. After a check, if the update was to the master branch, it executes a shell script.