This article is written for and published on SitePoint.
Jenkins is a great tool for continuous integration and continuous delivery. In previous articles we have seen how we can set up Jenkins and which of the many plugins might be interesting for you as a developer. In this article, we’ll guide you through seven ways to make sure you use Jenkins efficiently.
This article is based on a presentation given by Jenkins contributor Andrew Bayer, and is adapted here with permission.
Jenkins releases new versions frequently. It’s recommended to always use the latest LTS release and not to use the updates in between. The LTS release is thoroughly tested by the Jenkins team.
The same kind of rule also applies to plugins. They don’t have LTS releases, but many updates can occur. In general you should stick to the rule: If it’s working, don’t update it. New update may make features unstable and plugins behave differently.
Also make sure you create back-ups of your Jenkins server. You could back up all data, but that will cost you a lot of time and resources. Instead, you could decide to only back up your config files through scripts like this.
If you have a lot of teams or projects, you could create multiple Jenkins masters. For example you could create a master for your PHP projects and a separate one for your Android projects. This will make sure that your changes don’t affect all projects and you have only the plugins needed for those projects.
Break your jobs into multiple smaller jobs. Nothing is more annoying then a long build failing somewhere at the end. If you break your jobs into smaller jobs, you can easily restart one if it fails. Some plugins you can use to break up your jobs are:
* Parameterized Trigger + Conditional Build Step
* Build Pipeline plugin
* Workflow plugin
If you’re interested in a more in-depth explanation of the workflow plugin, have a look at one of our previous articles.
Jenkins comes with an integrated script console, allowing you to execute commands on the server. It’s a handy tool to debug Jenkins or to find information you need. An interesting plugin is the Scriptler plugin. With this plugin, you can save your favorite scripts for later reuse. You can also find an online script catalog here with predefined scripts like clearing the job queue.
For each build, you can also write your own build steps in the groovy language. This gives you more flexibility within your job, but it also means you’ll need to be more careful, because it gives you more control. You can also run scripts from the Scriptler catalog as a build step.
If you have a lot of projects, consider generating jobs automatically. Jenkins comes with a great REST API and a CLI tool to create new jobs. You can also dive into plugins like Workflow which we discussed recently to automate certain parts of the process.
Jenkins has a rich collection of plugins and it’s easy to get lost in the huge number that are available. It’s important to decide if you really need the plugin. Plugins can potentially break functionality within Jenkins which you might not expect. They can also slow down your jobs when building. Make sure to pick the right plugin for the right job. Don’t just install if you don’t need them.
Keep track of your list of plugins and uninstall any plugins which are no longer needed. This will keep Jenkins in good shape and free of bloat.
Also remember that some plugins come with global configuration settings. Don’t forget to check the global configuration after installing a plugin, as the default settings may not be what you want and could lead to unexpected behavior.
Jenkins offers you a REST API which you can use to integrate Jenkins with other tools. One of the best integrations is perhaps with your source control. You can easily combine Jenkins with Github or Gitlab for example. Each time a developer creates a pull request to your source code, Jenkins can be triggered to check the pull request for any flaws. This way, you can make sure you only accept pull requests that comply to your standards.
You can also integrate Jenkins with for example Gerrit. When reviewing the code within Gerrit, you will get additional feedback from Jenkins. You can check if everything is done the way you would like it to be and automatically merge the code in several branches.
A different approach is to integrate Jenkins with bugtrackers like Jira and Redmine. You can update issues when Jenkins builds an issue to keep a fingerprint. On the other hand, you can also automatically generate a change log based on all reported issues within this particular build.
Of course more integrations are possible. You could easily deploy your application on each build, for example. A good automated integration will make sure you can work on other things instead of performing those tasks manually.
Make sure you have easy to manage slaves. If you make sure you can replace them or add new ones without a hassle, your life will become a lot easier. If one slave dies, make sure it only takes a couple of clicks to get a new one up and running.
You can achieve this by either preparing virtual images you can use to install or you can manage your complete configuration through Puppet (module) or Chef (recipe).
You can also opt to make slaves more generic. This means you can run multiple different jobs on a single slave, making the slave more versatile. Do note however that you shouldn’t make your slave too complicated as noticed in the first point.
By putting the slaves in the cloud, you can even decide to activate slaves through an automatic system with the use of Docker, for example. This way, you don’t waste any resources and you can automatically scale when you need more slaves.
The last interesting point is to join the Jenkins community. Getting involved by either writing plugins or reporting issues will help improve Jenkins and will improve your Jenkins experience. Also, check out the Jenkins Subreddit, join a mailing list, log in to IRC for a chat, or sign up for the newsletter.
Jenkins is a great tool to set up your continuous integration or continuous delivery system. It’s important however to keep Jenkins in good shape, so it doesn’t affect your build process too much.