Many organizations have adopted the CI/CD methodology to deliver their products efficiently in an automated and incremented manner. CI and CD stand for Continous Integration and Continuous Delivery/Deployment. Continuous Integration refers to building your code, testing it through various test cases, and merging it into a version control repository. This ensures the incremental changes made in the code have been thoroughly tested and validated. These automated test cases reduce the possibilities of bugs or code conflicts.
Once the code has been built and tested, Continuous Delivery/Deployment ensures that the new release has been deployed in any of the environments like UAT, Production, etc. It delivers the packaged artifacts into these environments in an automated manner. It also ensures that the changes do not impact the application in the production environment.
CI/CD allows a bigger team to work on the same application and track its bugs and upcoming releases. These CI/CD pipelines can be implemented using several tools that are available in the market. One of the widely used tools for CI/CD is Jenkins.
What is Jenkins?
Jenkins is an open-source automation tool that allows organizations to create and automate their CI/CD pipelines. Jenkins provides over a thousand plugins that serve various needs of the software development life cycle. The integration of different tools with Jenkins has been possible because of the huge community support for Jenkins. These plugins are spread across different categories like source code management, development, build management, administration, etc. Some popular CI/CD plugins in Jenkins are Mailer, JUnit, Git, Pipeline, etc. The continuous integration facilitates the developers to merge the incremental changes. The continuous delivery/deployment facilitates the operations team to deploy the latest and most stable version to the production environment. Jenkins enables organizations to speed up their software development life cycles by automating all components of the life cycle like build, test, deploy, etc.
Get hands-on with Jenkins using KodeKloud
KodeKloud, a complete DevOps platform offers a Jenkins course for getting acquainted with the tool. The course syllabus covers all the important aspects related to the tool and also provides a hands-on with the tool to gain practical experience. The subscribers of KodeKloud can access the Jenkins playground for instant access to an environment with Jenkins pre-installed. The playground allows the users to get used to Jenkins and gain sufficient hands-on experience with it. By subscribing to the KodeKloud platform, the users can access the entire catalog consisting of over 30 courses and 35 playgrounds. Many of these courses are related to the DevOps domain and Jenkins is one of them. It includes courses on tools like Ansible, Terraform, Git, etc that can also be integrated with Jenkins using plugins.
Architecture of Jenkins
Jenkins can be used as a standalone server or as a distributed server. The standalone server is suitable for experimenting with the tool. It is not possible to manage multiple builds with a standalone setup. To manage multiple builds, Jenkins has to be deployed as a distributed setup that consists of a master node and agent nodes. The distributed setup can also be scaled according to the workloads that prevent any bottlenecks at the server level.
The main components of the Jenkins distributed architecture are:
- Master Node: The master node of Jenkins is responsible for the orchestration of all the pipelines submitted to it. All the configuration of the pipelines can be done using the user interface of the Jenkins master. Using this user interface, the users can download and connect with different plugins available. It communicates with the agent nodes to schedule the pipelines, monitor them, and show the output of the completed pipelines. It can also track the status of the running pipelines. It stores all the credentials that are required for accessing servers, S3 storage, etc.
- Agent Nodes: The agent nodes are responsible for the actual execution of the pipelines. All the steps mentioned in the pipelines are executed on these nodes. The agents need to be installed on the nodes so that the master node can connect with the agents. The agents can also be set up on different operating systems like Windows, Linux, and macOS. The agents can also be deployed dynamically using plugins like the Kubernetes plugin. Any number of nodes can be connected with the master node. The agent nodes are generally configured with labels associated with them. These labels are useful while mentioning where certain jobs should run.
Workflow of CI/CD pipelines
The above flowchart showcases a common CI/CD pipeline that teams implement for releasing their products. Such pipelines can be automated using Jenkins. First, the developers make required changes to the code and push the updated code to a repository. The CI/CD pipeline needs be to triggered by a certain action or event. For example, if there are any changes in the repository, the pipeline can get triggered. It can also get triggered periodically or when after certain pipelines are built. These trigger points are the starting point of the pipelines. After the code is compiled, the executable file goes through a set of test cases that are written in the repository. To build and test the code, build steps need to be provided in the jobs using the Jenkins user interface. The commands that need to be executed on the server are mentioned in these build steps. After the testing has been completed, the environment can be packaged into a docker image. This image can then be pushed to the production server for deploying the new release. Similar to the compilation and testing stage, the build steps need to be written for deploying the new release on the production servers.
For creating this pipeline, the users can create different jobs for each stage like build, test, and deploy. These jobs can also be linked to each other by using post-build actions. For example, after the compilation of code is completed, the job of testing the executable will automatically get triggered. Then after successful testing, the working environment can be packaged and deployed on the server. The flow of the pipelines may vary from team to team according to their projects and requirements. The users can also create views using the Jenkins dashboard. These views help in showcasing those jobs that are relevant to the project. In such a manner, the entire CI/CD pipeline can be automated using Jenkins.