I've finally decided to set up a Jenkins CI server for my Django projects earlier this week. For a long time, I've been deploying code via command line with Ansible. It worked very well but occasionally I find myself deploying from a coffee shop with unreliable connection, causing the deployment to get interrupted. Deploying instead from a virtual private server in the cloud would solve this and using Jenkins to do it was the first thing that came to mind as I've used it before at previous jobs.
I'm also at a point now where I'm maintaining 7 active Django projects with more coming soon, so the extra monthly cost to run the server is worth it for me. I just went with a $5/month DigitalOcean VPS and so far it's been running fine.
While the main reason for me to set it up was to ensure the connection is reliable during deployment, there are other benefits as well:
- trigger a build automatically when pushing code to Git (I only do this for my staging environments)
- get notified via email or other means (such as on a Slack channel) when a deployment is successful or has failed
- view your build history, see stats such as how long the deployment takes
- run scripts on the Jenkins server (especially useful for running scripts that take some time to complete, such as a script to automatically follow Twitter users, for example)
- schedule builds and other jobs (e.g. you may want to schedule a deployment to production involving database changes at a time when there aren't many active visitors)
- saves me time from entering my Ansible Vault passwords (I use a different one per project)
You can find the Ansible playbook here on GitHub: https://github.com/jcalazan/ansible-jenkins
The playbook was tested on Ubuntu 14.04 x64. Note that I included Docker installation in the playbook as I use Docker to run my tests. It's works quite well as spinning up Docker containers is very fast plus it allows me to test in an environment with a similar setup to the servers (e.g. running the tests using PostgreSQL instead of SQLite). I may write a separate blog post about this set up in the future.