DevOps with Jenkins

Jenkins is an open-source automation server commonly used for building, testing, and deploying software. It facilitates continuous integration and continuous delivery (CI/CD) by automating the repetitive tasks involved in the software development process. Jenkins supports the automation of building, testing, and deploying code changes, making it easier for development teams to collaborate and release software more efficiently.

The official website for Jenkins is https://jenkins-ci.org/. Click the given link to download the Jenkins WAR file. Click on the Long-Term Support Release tab in the download section for the latest Jenkins release.


System Requirements

Jenkins Installation

Installation and configuration on a Windows Server:

1. Open the command prompt. From the command prompt, browse to the directory where the jenkins.war file is present and run the following command,
D:\>Java –jar Jenkins.war

2. After the command is run, various tasks will run, one of which is the extraction of the war file which is done by an embedded webserver called winstone.
D:\>Java –jar Jenkins.war
Running from: D:\jenkins.war
Webroot: $user.home/ .jenkins
Sep 29, 2021 4:10:46 PM winstone.Logger logInternal
INFO: Beginning extraction from war file

3. Once the processing is complete without major errors, the following line will come in the output of the command prompt.
INFO: Jenkins is fully up and running

Installation and configuration on a Linux Server:

1. Log in to the server and update it
sudo apt-get -y update

2. Install java
sudo apt-get install -y default-jdk

3. Head over to http://pkg.jenkins-ci.org/debian/ and get the download link for Jenkins 2 Ubuntu version and download it using wget command.

4. Install the package
sudo dpkg -i jenkins*

5. If you face any dependency error while installing the package, you need to execute the following command to rectify it.
sudo apt-get -f install

6. To add Jenkins to the boot menu, open /etc/rc.local file and add the following to the file.
/etc/init.d/jenkins start
Now you will be able to access the Jenkins server on port 8080 from localhost or using the IP address

7. You need to provide the administrative password. You can get the password using the following command.
sudo cat /var/lib/jenkins/secrets/initialAdminPassword
Copy the password and click continue.

8. Next, you will be asked to configure plugins as shown below. Select “Install Suggested Plugins” option. This will install all the required plugins for building your projects. It will take few minutes to install the plugins.
Jenkins 2.0 plugin configuration

9. Once installed, You need to create a user with password and click “save and finish”
Jenkins 2.0 user configuration

10. Click “Start Using Jenkins” and it will take you to the Jenkins Dashboard. Log in using the username and password that you have given in step 7.

11. If you want to build java maven project, you need to install maven using the following command.
sudo apt-get install -y maven2

Once Jenkins is up and running, one can access Jenkins from the link – http://localhost:8080

Jenkins GitHub Integration

Install Git:
Assuming you have completed those basic steps, we shall now move on to Plugin management. Jenkins has outstanding plugin support. There are thousands of third-party application plugins available on their website. To know if Jenkins supports the third-party applications you have in mind, check their plugins directory at https://wiki.jenkins-ci.org/display/JENKINS/Plugins. 

In this you will learn: 
    • Installation of Plugins in Jenkins 
    • Install GIT Plugin 
    • Integrating Jenkins with GitHub

  • Installation of Plugins in Jenkins:
Jenkins comes with a pretty basic setup, so you will need to install the required plugins to enable respective third-party application support. GitHub is a web-based repository of code which plays a major role in DevOps. It provides a common platform for multiple developers working on the same code/project to upload and retrieve updated code, thereby facilitating continuous integration. Jenkins needs to have GitHub plugin installed to be able to pull code from the GitHub repository. You need not install a GitHub plugin if you have already installed the Git plugin in response to the prompt during the Jenkins' installation setup. But if not, here is how you install GitHub plugins in Jenkins and pull code from a GitHub repository.

  • Install GIT Plugin:
Step 1: Click on the Manage Jenkins button on your Jenkins dashboard:

Step 2: Click on Manage Plugins:
Step 3: In the github integration Plugins Page

    1. Select the GIT Plugin, GitHub and GitHub Integration Plugin.
    2. Click on Install without restart. The plugin will take a few moments to finish downloading                       depending on your internet connection, and will be installed automatically.
    3. You can also select the option Download now and Install after restart button. In which plugin is             installed after restart.
    4. You will be shown a "No updates available" message if you already have the Git plugin installed.

Step 4: Once the plugins have been installed, go to Manage Jenkins on your Jenkins dashboard. You will see your plugins listed among the rest.

  • Integrating Jenkins with GitHub
We shall now discuss the process of integrating GitHub into Jenkins in a Windows system.

Step-1 Create a new job in Jenkins, open the Jenkins dashboard with your Jenkins URL. For example, http://localhost:8080/ Click on create new jobs:
Step-2 Enter the item name, select job type and click OK. We shall create a Freestyle project as an example.
Step-3 Once you click OK, the page will be redirected to its project form. Here you will need to enter the project information:

Step-4 You will see a Git option under Source Code Management if your Git plugin has been installed in Jenkins:
NOTE: If the Git option does not appear, try re-installing the plugins, followed by a restart and a re-login into your Jenkins dashboard. You will now be able to see the Git option as mentioned above.

Step-5 Enter the Git repository URL to pull the code from GitHub.

Step-6 You might get an error message the first time you enter the repository URL. For example:

This happens if you do not have Git installed in your local machine. To install Git in your local machine, go to https://git-scm.com/downloads

Download the appropriate Git file for your Operating System, in this case, Windows, and install it onto your local machine running Jenkins. Complete the onscreen instructions to install GIT.

Step-6 You can execute Git repositories in your Jenkins once Git has been installed on your machine. To check if it has been successfully installed onto your system, open your command prompt, type "Git" and press enter. You should see different options come up for Git:

This means that Git has been installed in your system.

Step-7 Once you have everything in place, try adding the Git URL into Jenkins. You will not see any error messages:
Git is now properly configured on your system.

In the next session we learn other functionalities of Jenkins such as,
  • How to Create Builds with Jenkins
  • How to Create Users & Manage Permissions in Jenkins
  • How to Set-up Jenkins Master/Slave

Comments

Popular posts from this blog

Cloud Data Storage

Agile Methodology With Waterfall Model

CLOUD COMPUTING