It’s interesting how many places still don’t use continuous integration tools like Jenkins and how many places don’t automate their deployment systems. If that all sounds like
goobledegook to you, or if it makes sense but you’ve never used anything like it then
this post is for you.
Life before Jenkins
Before we talk about Jenkins I think it’s worth talking about my experience of life before
Jenkins, which will be familiar to a lot of people. Here’s what might have happened in an
average working day pre-Jenkins:
- I would write some code and commit it
- Occasionally a project manager or designer or someone equally focused on interrupting my programming would ask to see the latest version of the project
- I’d update my code and show them and then they’d ask if they could have a play with it from their computer
- 4. I would then interrupt someone in charge of deployment and would ask them to deploy it somewhere
- This person would probably groan (because they’re in the middle of something) and say that they could do it in 15 minutes
- The project manager would roll their eyes and sit at their desk reading emails or updating a GANTT chart (or whatever project managers do) for 30 minutes (because the task the developer was doing took twice as long as expected)
- The deployer would open their FTP program and copy files up to the dev server, or SSH the files up or whatever, possibly missing a few files the first time and then having to do it a second time
- The project manager would complain the work he wanted wasn’t there.
- The deployer would realise he hadn’t updated his code and do the process again
- Three hours later the same thing the process would start again…
It’s a slow, error prone, painful process and we haven’t even talked about deploying to staging or live environments yet. A major problem is also that a lot of people are unsure what the exact state of the project is because they never know if what they’re looking at is up to date.
Jenkins to the rescue!
Here’s how that above process would work with Jenkins running.
- I write some code and commit it.
- Moments later the code is on a development environment without anyone having to do anything.
- The project manager looks at the development environment whenever they want to knowing it has the latest work on it
- The QA tester checks the release on the development environment and clicks a button in Jenkins to deploy to the staging environment.
Simple! (I even added an extra staging deploy part in there to look extra clever)
So, what is Jenkins?
The Jenkins CI (that’s its proper name) website describes it as “an awardwinning
application that monitors executions of repeated jobs, such as building a software project or jobs run by cron.”
So Jenkins is a tool that can be used to do any kind of repetitive task, but the added bonus of Jenkins is that these repeated tasks can be monitored and report information and make it easy for people to initiate these tasks or have them initiated automatically.
So for example, you might have a .Net project which is the server aspect to a project with iOS and Android apps. Jenkins can build and deploy the .Net project whenever changes are made so the latest version is available. The iOS and Android applications can also be built when code is changed and can be deployed via tools like TestFlight.
The “continuous integration” part comes into play when you have multiple developers working on a project. Jenkins is constantly building the latest version of the project from all developers' code so your work is being integrated (and deployed) continually.
I’m not going to get too deep into technical details since you can get those from the Jenkins website or via the excellent “Jenkins: The Definitive Guide” book but I’ll talk about what Jenkins would for a .Net project with a simple HTML/CSS/JS frontend codenamed
“Gumboots”.
- In Jenkins there is a “Gumboots” job which has been configured with the details of a
GitHub repos containing the code for the project
- GitHub has been configured to hook into your “Gumboots” job whenever the code
changes
- A developer pushes some code to the GitHub repos. GitHub notifies Jenkins about the
new code.
- Jenkins gets the new code and runs a build.
- Jenkins has been configured to do a few things when the build is run:
a) It runs a load of automated test cases
b) If those pass it then builds the project using the MSBuild plugiN
c) If that works it then runs a Gulp tasks on the CSS and Javascript to minify them and concatenate them.
- If that is all successful, then it will deploy the new code over SSH to the developmenT server
If any of these steps fail, then Jenkins will send an email with details of the problem to people involved in the project and most importantly to the person who wrote the last piece of code that may have broken the build.
Setting up jobs for Android and iOS applications is very similar and follows the pattern of “get code”, “build code”, “deploy code”.
There’s even a Chuck Norris plugin to give you extra feedback about the state of your jobs. Now really, what more could you want?
What next?
I’ve described a basic, but powerful Jenkins job set up. This will do a lot for you, but it can be taken further.
The kind of things that you can get Jenkins to do that might be useful for you are:
- Create a pipeline which pushes a build to dev automatically, then to staging after a
manual QA check and then to live when a release is required.
- Integrate Jenkins with an issue tracker like JIRA so that as Jenkins deploys code it tells JIRA what issues have been released
- Get Jenkins to automatically run migration scripts on your databases when deploying and also get Jenkins to do one click rollbacks of your project if things go wrong
- Create a parameterised Jenkins job which takes some input and then spins up a new
server based on that input for you.
There are lots of other tools similar to Jenkins of varying complexity and approaches. These tools are becoming increasingly popular as cloud services which can handle platform
configuration and provisioning as well as the code deployment aspect.
Jenkins has always worked well for me. It’s not the best looking tool, but it has a large
community, it’s simple but can be complex and it has a load of plugins for it.
Hats off to Kohsuke Kawaguchi and the Jenkins team for building us something so useful.
Disclosure: I am a real user, and this review is based on my own experience and opinions.