Jenkins is a self-contained, open-source automation server which can be used to automate all sorts of tasks related to building, testing, and delivering or deploying software. It’s a tool that’s used by developers and DevOps teams alike to implement continues integration, continuous delivery, and continuous deployment methodologies.
The best part about Jenkins is that it’s free, open source, and has a huge commitment of users and contributors. There are over 1,500 plugins available to help you customize Jenkins to your needs. Whether you are building a simple PHP app or a complex microservices architecture, Jenkins can handle it.
So, let’s get started, by the end of this article, you will have a solid understanding of Jenkins and how to use it to supercharge your development workflows.
What is Jenkins and why is it useful for automation?
Jenkins is an open-source automation server that lets you orchestrate your build, test, and deployment pipelines. Using Jenkins, you can automatically build and test your software projects continuously, meaning whenever a change is made and committed.
For example, say your team pushes new code to GitHub, your projects repository. Jenkins will notice this new code push, checkout latest code, build it, and run any automated test you have set up. If everything looks good, Jenkins can even deploy your new code to production!
This continues integration and delivery (CI/CD) process powered by Jenkins helps developers save time and catch issues early on. Some of the useful things you can do with Jenkins include:
- Build your projects: compile code, package binaries, etc.
- Run unit and integration test
- Deploy to environments: staging, production, etc.
- Create complex pipelines: Chain multiple builds together
- Integrate with other tools: GitHub, Maven, Docker, etc.
- Distribute builds across nodes: Scale your builds across multiple machines
The best part is Jenkins has a huge ecosystem of plugins to support almost any build or deployment tool you can imagine. With a little setup, Jenkins can become the hub of your automation efforts and keep your team productive. If you are looking to level up your development process, Jenkins is a great please to start.
Create a sample pipeline for CICD with Jenkins:
To set up continuous integration and continuous deployment CICD with Jenkins, you will want to create a pipeline. A pipeline is a suite of plugins that orchestrate doing something useful with your software, like building, testing, and deploying it.
Let’s walk through making a simple pipeline. First, install the Pipeline plugin in Jenkins. Then create a new pipeline item and select ‘Pipeline script from SCM’. Choose your
source code management system, like Git, and enter the path to your Jenkinsfile. This file will contain the steps in your pipeline.
Your first stage should be building your code. You might have steps like:
node {
stage(‘Build’) {
}
sh ‘npm install’
sh ‘npm run build’
}
This uses the NodeJS plugin to run npm install and npm run build to build your app.
Next, add a stage to test your code. You could run:
stage(‘Test’) {
sh ‘npm run test’
}
To deploy, add another stage:
stage(‘Deploy’) {
sh ‘npm run deploy’
}
With a pipeline set up, Jenkins will automatically build, test and deploy your app every time you push code to your SCM. This automation and continuous feedback are the power of CI/CD with Jenkins!
Using a tool like Jenkins for CI/CD allows developers to integrate changes to a project and provides quick feedback. Setting up a simple pipeline to build, test and deploy your app is a great way to start leveraging the power of Jenkins.
Key Jenkins Plugins for Automating Builds and Deployments:
Jenkins offers several useful plugins to help automate your build and deployment processes. Here are a few of the key ones to know:
Git Plugin:
This plugin integrates Git with Jenkins, allowing you to pull source code from Git repositories directly in your Jenkins builds. You can define Git URLs and credentials right in your Jenkins jobs. The Git plugin is a must-have for any project using Git for version control.
Maven Plugin:
For Java projects using Maven for building, the Maven plugin provides tight integration with Maven. You can install Maven, define Maven settings, work with Maven repositories, and build Maven-based projects directly from Jenkins. This eliminates the need to install Maven manually on agents.
Docker Plugin:
To build Docker images and work with Docker registries, use the Docker plugin. This plugin lets you build Dockerfiles directly from Jenkins, build images, push and pull from registries like Docker Hub and Google Container Registry, and more. For any project deploying to Docker containers, the Docker plugin is essential.
Pipeline:
The Pipeline plugin, formerly known as the Workflow plugin, lets you define build and deployment pipelines directly in Jenkins. You can create scripted or declarative pipelines to orchestrate even complex build flows. Pipeline is a very powerful way to automate CI/CD workflows in Jenkins. Many of the other plugins on this list work with and enhance Pipeline functionality.
Blue Ocean:
Blue Ocean is a redesign of the Jenkins UI that provides a modern, streamlined experience for creating and visualizing Pipelines. It features pipeline editors, visual timeline views, and integrated Git version control among other useful tools for CI/CD management. Blue Ocean works with and requires the Jenkins Pipeline plugin.
Using a combination of these key plugins, you can fully automate builds, tests, and deployments for any software project. Jenkins has a vast ecosystem of other plugins as well to suit nearly any need.
How to Set Up Jenkins for Automated Testing
To set up Jenkins for automated testing, there are a few steps you’ll need to take. Jenkins is an open-source automation server that can help you build, test, and deploy your software projects continuously.
Install Jenkins:
The first thing you’ll need to do is install Jenkins. You have a few options here:
- Download and run Jenkins as a .war file. This is good for testing Jenkins, but not recommended for production use.
- Use Docker to run Jenkins in a container. This is a popular option to get up and running quickly.
- Download a Jenkins .deb or .rpm package to install on Ubuntu/Debian or RedHat/CentOS. This is good for production use.
Once Jenkins is installed, you’ll be able to access the web UI and begin configuring your installation.
Create a Jenkins user:
Next, you’ll want to create a Jenkins admin user to login to the web Ul. Go to the Jenkins web UI, select “Manage Jenkins” then “Manage Users”. Click “Create User” and enter a username, email, and password. Be sure to give the user “Admin” permissions so they have full access.
Install plugins:
Jenkins has a robust plugin ecosystem that allows you to extend its functionality. Some important plugins for testing are:
- The Git plugin to checkout source code from Git repositories
- The Pipeline plugin which allows you to define pipelines to build, test, and deploy your projects.
- The Cucumber Report plugin to parse Cucumber test reports.
Go to “Manage Jenkins” then “Manage Plugins” to browse and install plugins. Restart Jenkins after installing new plugins.
Create a sample pipeline:
Now you’re ready to create your first Jenkins pipeline! A pipeline defines the steps to build, test, and deploy your project. Go to the Jenkins dashboard and select “New Item”. Enter a name and select “Pipeline” then click OK. In the pipeline section, enter:
***groovy
node{
git ‘https://github.com/your/repo.git
}
sh “npm install && npm test
This simple pipeline will checkout your code from GitHub and run npm install followed by npm test to execute any tests you have. Save the pipeline and build it to see it in action!
Jenkins powers many continuous integration and delivery pipelines. With some setup, you’ll be automating builds, testing, and deployments in no time! Let me know if you have any other questions.
Best Practices for Maintaining and Securing Your Jenkins Server
To keep your Jenkins server running smoothly and securely, follow these best practices:
Update Jenkins regularly:
New versions of Jenkins are released frequently, containing security patches and bug fixes. Update Jenkins at least once a month or enable automatic updates to always have the latest version.
Manage user access:
Only grant administrator access to trusted users. For normal users, give them the least amount of permission needed to do their jobs. Regularly review user access and disable any inactive accounts.
Use a reverse proxy:
A reverse proxy sits in front of Jenkins and handles tasks like authentication, caching, load balancing, and SSL termination. This makes Jenkins less exposed and more secure. Popular options are Apache httpd, Nginx, and Traefik.
Monitor for threats:
Use tools like audit trails, login monitoring, and the Jenkins warnings plugin to detect unauthorized access or abnormal behavior. Review logs frequently and take action quickly if any threats are detected.
Keeping your Jenkins server secure and maintained may require ongoing effort, but it will give you peace of mind knowing your CI/CD pipelines and data are protected.
Implementing these best practices and monitoring your Jenkins instance regularly will help keep it running in tip-top shape for a long time to come.
Conclusion:
So, there you have it, an introduction to Jenkins, the open-source automation server that has revolutionized continuous integration and continuous delivery. You’ve learned how easy it is to get up and running with Jenkins, build your first automation pipeline, and start reaping the rewards of a streamlined development process. Now you’ll be able to spend more time on the fun stuff – coding and creating – and less time stuck in the integration and deployment nightmare. Best of all, with a powerful, flexible, and customizable tool like Jenkins at your disposal, the possibilities for automation are endless. The future of software development is here.

Mohammad Saad
Associate Consultant