Building a basic jekyll git and jenkins build pipeline

This website used to use Jekyll as its static site generator. I prefer working with static site generators as it means the website needs very little resources and isnt prone to as many vulnerabilities as other CMS’s. This is how i setup automated deployments of this website using Jenkins.

Static site generators are a bit different from the likes of wordpress, where you are just entering content directly on the website. With jekyll, you write your posts in Markdown then trigger Jekyll to build it into HTML. Then you upload that HTML to your server.

For me, there are multiple benefits to this, the main ones being its VERY easy to source control all your code and its easy to automate. This is what this post is about.

For this automation, im using several difference servers / devices:

  • My laptop – This is where i write the markdown
  • Gitlab server – This is a locally hosted VM on one of my servers.
  • Jenkins Server – This is again locally hosted.
  • VPS – The VPS you are reading this from.

NOTE This is far from perfect. I need to add in more advanced things like automatic roll-backs, things like that.

Current working pipeline

So this is how things currently work:

1) I write something on my laptop.
2) I push that to my git repo.
3) Gitlab tells jenkins that theres a new commit and triggers a build.
4) Jenkins cleans its workspace, pulls in the latest code.
5) Jenkins triggers a ‘jekyll build –destination x’.
6) Jenkins rsyncs a copy of the current website from the server, stores it locally in a directory with the time and date.
7) Jenkins rsyncs the new build up to the webserver and sets the correct permissions.
8) Jenkins tell gitlab the build passed, and alerts me on slack / mattermost that the build passed.

Again, there are more things i want to add to this, i want to check im getting a HTTP-200 from the webserver, then if im not, restore the old backup. I’d also like it to parse the index.html to ensure the newest post is at the top and has actually been added.
This is still a WiP but so far its working as expected.

The setup

Here are the screenshots from Jenkins which show the build process and also the oneliners im running to do things like configure permissions.

Testing

Once everything is setup and you are ready to test, just commit at change to git, this should trigger the entire process to kick off. Which is exactly what im going to do with this post now!