Jenkins 101: Getting started with Jenkins
Who or What is Jenkins
Jenkins is a free and open-source CI/CD server. The Java-based application serves as a platform for development, testing, and release.
So, Why Jenkins ?
Gitlab CI/CD, GitHub CI/CD, CircleCI, Travis CI, Bitbucket pipeline, etc. are just a few of the CI/CD technologies poopularly used. Depending on the situation, several tools can be used to their full potential. However, Jenkins has a few advantages that makes it preferable in comparison to its rivals.
To begin, as we shall see when we perform the setup, installation and configuration are quick and easy. The platform’s web-based administration is user-friendly, allowing for a wide range of customization in construction processes. For more versatility and personalization, it makes use of a plugin ecosystem. Scalability is provided via Jenkins’ decentralised build agents and executors. Finally, the thriving community of users and thorough online documentation are invaluable resources.
The Jargon of Jenkins
1. Jenkins Master Node
The Jenkins administrative dashboard is hosted on the Jenkins controller/master. It provides a web-based administrative portal for setting up build jobs, pipelines, and plugins. The master coordinates the scheduling and distribution of build jobs to the build agents.
2. Jenkins Build Agent
A build agent, also called a slave, is a dedicated server that the Jenkins master communicates with by sending it build task dispatches. As shown in the above graphic, each Agent is capable of running its own OS.
3. Build Project
The Build project defines the parameters for a specific software’s build setup. There are different build requirements for different project types. The default build project on Jenkins are:
- Freestyle project
- Multi-configuration project
- GitHub Organization
- Multibranch Pipeline
Each project choice is described in detail on the Jenkins UI.
Grouping together various build agents based on user-defined metadata. Labels can be used to categorise Build Agents in a variety of ways, such as by operating system or by type of build technology.
Labels all machines that can run a given build pipeline or project. The location of the execution can now be determined. Scripted pipelines make use of nodes.
Labels all machines that can run a given build pipeline or project. The location of the execution can now be determined. The Declarative pipeline employs agents.
Created document when a construction has been completed. It could be a.NET assembly, a Java JAR, or even a simple ZIP archive. Artefacts are considered immutable and should not be changed outside of the construction process that originally created them. A fingerprint, which is a checksum of the relevant Artefact file, is used for tracking and tracing purposes.
A pipeline is a modelling concept that represents and encapsulates the fundamental building logic and process. Jenkins offers two distinct syntaxes for constructing pipelines:
- Declarative Pipelines
A Syntax with a strong point of view; the rules are more clearly laid out and rigid. They’re less adaptable than scripted pipelines, but they’re simpler to use if you don’t know Groovy.
- Scripted Pipelines
Developed using the Groovy programming language, it allows you to make highly individualised processing pipelines. However, you will need Groovy expertise to get anything done. Those in charge of building and releasing software who aren’t familiar with Groovy may not want to go through the additional learning curve.
Nowadays, declarative pipelines are more used as it is easier to learn and works with most SCM tools such as Gihub, Bitbucket and more.
Automated methods known as a CI/CD (Continuous Integration/Continuous Deployment) pipeline are used to continually integrate code changes, build and test applications, and deploy them to production. Getting updates out to users quickly and reliably is the main focus of a CI/CD workflow.
The various steps that make up a typical CI/CD pipeline are as follows:
- Code Integration: In this stage, developers combine their individual code updates into a central repository.
- Build: In this stage, the CI system compiles the code and executes any tests at this point.
- Test: This phase involves running various tests on the code, such as unit tests, integration tests, and full-stack tests.
- Deployment: In this stage, The code is released into a live (prod) or test (staging) environment
- Monitoring: This is usually the last stage. At this stage, the system checks in on the running application to make sure everything is running smoothly.
Used to divide the entire pipeline into smaller, more manageable chunks. Identifying discrete phases has various advantages:
- Provides the framework for the pipeline’s creator to implement order.
- Used to display build status as the build is being executed.
Clone, Build, Test, Packaging, and Deployment are all examples of typical phases in the CI/CD lifecycle.
A pipeline stage can be made up of many pipeline steps.
A pipeline step specifies a single build task and what should occur. A pipeline stage often encompasses several pipeline phases.
A dedicated file system directory where build work for the current pipeline or build process is conducted. When debugging builds, this directory and its subdirectory structure are useful to investigate. The workspace will be generated on the build agent that the pipeline or build job is configured to run on.
This refers to another pipeline or build job that will be triggered as a result of the current pipeline or build job.
This job refers to the pipeline that started the current pipeline or build job.
A blog post on how to install Jenkins on AWS can be found here.
Remember to save the ”
initialAdminPassword” value for the first time you log in.
To install commonly used plugins, select Install suggested plugins:
After downloading the plugins, enter your credentials and click ”Save and Continue” to access your dashboard.
Now that we’ve covered the fundamentals of Jenkins, let’s get our hands dirty with some tasks and projects from the #90DaysofDevops challenge, which runs from Day 22 to Day 29.
Create a sample freestyle pipeline that prints “Hello World!!
- Using the Freestyle project, make a new object. Give it a name, for example,
HelloBuildJob. On the bottom right, click
- After you’ve created the project, go to the Configuration area and then to the ”
Build Steps” section, where you’ll add the ”
Execute Shell” option.
- Add the shell command to print “Hello World!!”
echo "Hello World!!
Now, click the ”
Build Now” button. If everything is in order, you will see a green tick with the #1 next to it, indicating that the first build was successful.
- Click on the build number and look for the ”
Hello World” text on the Console page.
That concludes the first project!
We will start first by creating an agent for our app. We will create a Jenkins freestyle project for this task.
- App is a to-do app that may be found on this git repo.
- As previously said, we will create a new item called toDoApp and select Freestyle Project as the build job. Select OK.
- In the Configuration tab, select Github Project and enter the GitHub URL. Repeat the process in the ”Source Code Management” section.
- Because the source code is in the default master branch, leave the rest as it is by default. If not, feel free to switch to the correct branch.
- Add the command to create a Docker image for the container to the
- Also, add a second command to run a container using the image you just created in the previous step.
docker build -t todoapp . docker run -d --name todoapp_c -p 8000:8000 todoapp
- You can now build the project by clicking the ”
Build now” button.
- We can examine and notice that the source code has been cloned on the machine by inspecting the workspace folder under
- Create a
Jenkins projectthat will perform the command ”
docker-compose up -d” to start the several containers defined in the docker compose file.
- Create a file called
docker-compose.ymlin your project folder.
- Add a ”
docker-compose down” build step to destroy any containers defined in the docker-compose file. This helps to avoid containers that are incompatible.
- Now, add the ”
docker-compose up -d” command to spin up new docker containers as per the content of the docker-compose file.
The container has been launched as seen below:
That’s it for today!!!👋
Today we created our very first job with Jenkins our CI tool. We also looked at some simple jobs that we created using Jenkins.
For our next article, we will create a complete CI/CD Project with Jenkins as our CI tool.
Thank you for taking the time to read this! If you like the article, please clap (up to 50 times!) and connect with me on LinkedIn and Medium to remain up to speed on my future articles. 😅