In this tutorial, we are going to learn the basics of Jenkins. It is the most popular, open source Continuous Integration / Continuous Delivery (CI/CD) tool written in Java with built in plugins for almost any combination of languages and source code repositories using pipelines. It builds and tests our software projects that make it easier for developers to incorporate improvements to the project and make it easier for users to get fresh construction.
What is Continuous Integration and Continuous delivery?
Continuous Integration (CI): Continuous Integration (CI) is a practice of software development, where developers often integrate their work with the Integration branch of the project and create a build.
Continuous integration is a major step in the DevOps lifecycle, it makes the development testing and deployment of applications easier and faster. There are a number of continuous integration tools like below
- Bamboo
- Apache
- Travis CI
- Jenkins
- Buddy
- TeamCity
Among them Jenkins is the most popular CI tool.
Continuous Delivery (CD): Continuous Delivery (CD) is an extension of continuous integration to ensure you can easily and sustainably bring new updates to your customers or software.
CONTENTS:
1. Installing Jenkins:
Firstly before installing Jenkins we need to download Java, as it is a Java based program. If you have already JAVA make sure by typing “JAVA” in command prompt and skip here.
To install Java click here
Click “Java Download”
Click “Agree and Start Free Download”. After downloading, install the Java software.
Downloading Jenkins:
Here is the official website of Jenkins Download
Click the “Generic Java package(.war)“, this is best to install on any operating system
Once you downloaded the file, go to the folder where you downloaded the file and “Hold Shift + Right Click on Mouse”
In this, click the option “Open PowerShell window here”.
Once you clicked it, it will display the Windows PowerShell window. Now copy the code Java –jar Jenkins.war to the Power Shell
Now it will ask access for the software, click Allow access and give access.
After clicking allow access, the powershell will install Jenkins to your system
Once installed, copy the generated password from powershell like the above.
Now, Browse here
Unlock Jenkins using the password copied from PowerShell and click “Continue”
Here select the “Install suggested plugins”, It will automatically install most popular and most used plugins and wait till the installation is finished.
After installation, enter the details asked and click “Save&Continue”. Make sure to remember username and password
Click “Start using Jenkins“. Now installation has been successfully completed
2. Creating a New Job
Click New Items in the menu to create a new job,
In here type the name of the project and select the type of project. It supports six types of projects.
Freestyle project
Freestyle means unregulated or improvised. A Jenkins freestyle project is a project covering several operations. It can be a build, a running script or even a pipeline.
Pipeline project
The pipeline project is a plugin suite that supports the implementation and integration of continuous delivery pipelines into Jenkins.
Multi Configuration project
The multi Configuration project just like a working template, it begins multiple sub jobs depending on the configuration, aggregates all the test results and shows them in the status page
Folder
A folder project allows users with configuration permission to define properties for a folder that can then be used by any jobs it contains or by any of its subfolders
GitHub Organization
To take the project from the GitHub organisation
Multi branch Pipeline
Multi branch pipeline helps you to apply numerous Jenkins files to different divisions of the same project. Jenkins automatically identifies, manages, and executes Pipelines for branches containing a Jenkins file in source control in a Multi branch Pipeline Plan.
3. Configuring New Jobs
1. General:
- Description: Description of the Project
- Discard old builds: This dictates when, if ever, the record builds should be discarded for this project.
- Github Project: To choose the project if it’s from Github
- This project is parameterized: Parameters allow you to prompt users for one or more inputs going into a project. You may have a project, for example, that runs tests on demand by allowing users to upload a binary zip file to be tested.
- Execute concurrent builds if necessary: When this option is checked, multiple builds of this project may be executed in parallel.
2. Source Code Management:
- None: No source code management
- Git: Repositories management like GitHub
3. Build Triggers:
- Trigger builds remotely (e.g., from scripts): Enable this option if you wish to activate new builds by accessing a certain predefined URL
- Build after other projects are built: Set up a mechanism so that a new build is planned for this project when any other projects finish building.
- Build periodically: Provides a time based like feature to periodically execute this project.
MINUTE | Minutes within the hour (0–59) |
HOUR | The hour of the day (0–23) |
DOM | The day of the month (1–31) |
MONTH | The month (1–12) |
DOW | The day of the week (0–7) where 0 and 7 are Sunday. |
- Poll SCM: Configure Jenkins to poll changes in SCM.
4. Build Environment:
- Delete workspace before build starts: Deletes the workspace from it before the build starts.
- Use secret text(s) or file(s): Allows you to take credentials of various kinds and use them from measures in shell building.
- With Ant: Prepares an environment for it to run builds using Apache Ant.
- Build: To select what type of build.
- Add post build action: To add an extra feature to the project.
4. Checking the builds
So, I configured a project to run a command every minute.
In the Build Trigger Configuration, I made it to “Build Periodically” and used “* * * * *” as my period which indicates one minute [Format: MINUTE HOUR DOM MONTH DOW]
In the Build Command, I typed echo “Hello World”, to run the build and command “Hello World” every minute.
After saving it. It will build the job every minute as shown below screenshot
To check the output select any build, (In my case I selected the 3rd build) and click Console Output
As you can see, it is displaying “Hello World” in the console.
You can also configure your project later using Configure in the menu
5. Adding Plugins
In Jenkins, you can add extra plugins from the software online. To add plugins Go to the main menu, click “Manage Jenkins” and select “Manage plugins“
Now click the available tab, and search for the plugin you need. I need to install the role based Authorization Strategy plugin I have searched for “role“.
After selecting the plugin, click “Download now and install after restart” which is recommended for plugin installation.