Linux | Cloud | DevOps | Scripting

Breaking

Wednesday 26 June 2019

Installation of Jenkins Server


Jenkins:

Jenkins is a vastly used continuous integration tool for the IT industry which is built and used around plugins. Jenkins is an Open Source automation server, which provides hundreds of plugins to support building, deploying and automating any project. Jenkins is a Continuous Integration and Continuous Delivery tool. 

➔ Who can use Jenkins:

Everyone in the field of Software Development can use Jenkins. Like:

  1. Application Developers
  2. Web Developers
  3. System Test Groups
  4. IT Operations
  5. System Engineers
  6. DevOps Engineers

 ➔ Advantages of Jenkins:

There are below mentioned some basic advantages of Jenkins:

  1. It's open source. So as compared to other CI options Jenkins is better than that. 
  2. It's easy to set up and configure.
  3. Jenkins is flexible with too much plugin support. If we want any plugin which is not available according to us, we can write our own. It’s written in Groovy language, which a Java-based language. 
  4. Jenkins can work in any environment.
  5. Jenkins doesn’t use a lot of resources. It has a user-friendly Dashboard which can be used at any platform. 

➔ Necessities to install Jenkins:

  1. Java
  2. Supporting OS (64 bit)

These two are basic necessities to install Java in any OS.

Install Jenkins:

Steps we need to follow to install Jenkins:

  1. Create a new VM for Jenkins in GCP
  2. Install Java and set the environment variable in this VM
  3. Install Jenkins package and start the service
  4. Run Jenkins in browser
  5. Unlock Jenkins
  6. Configure System
  7. Global Tool Configuration
  8. To use Maven projects in the future, we need to install Maven
  9. To use Git in the future, we need to install Git

Step 1: Create a new VM for Jenkins in GCP named 'jenkins-server':

GCP ➔ Compute Engine ➔ VM Instances ➔ Create Instance ➔ Name: jenkins-server ➔ Region: asia-south1 (Mumbai) ➔ Zone: asia-south1-a ➔ Machine type: n1-standard ➔ CPU Platform: Automatic ➔ Boot Disk: CentOS 7 (from here we can select the operating system) ➔ Boot Disk Type: Standard persistent disk ➔ Size: 10 GB ➔ Select ➔ Service Account: Compute Engine default service account ➔ Access Scope: [*] Allow default access ➔ Firewall: [*] Allow HTTP traffic ➔ [*] Allow HTTPS traffic ➔ Create.

Step2: Install Java and set the environment variable in this VM:

Jenkins requires minimum Java 7 to be installed. It's recommended to install Java 8 or latest version. Before installing Java first verify Java is installed in our computer or not?

$ java -version

If Java is already installed, this command will display the current version of Java. If we do not have Java installed in our PC or installed Java version is less than 7, then we need to install Java on our PC.

➔ Java Installation in Windows:

1. Search in Google, 'install java'. Navigate to official Oracle link. Right now I am downloading Java from the below mentioned link:

https://www.oracle.com/technetwork/java/javase/downloads/jdk12-downloads-5295953.html

Download & Install Java jdk according to OS:

JAVA Installation
Fig: JAVA Installation

Accept License Agreement and then download Windows 64-bit zip file  Extract files.

2. Configure JAVA_HOME environment variable.

JAVA_HOME environment variable points to the installation path of the Java Development Kit. It required by other applications which use Java.

- Do right click on My Computer and select Properties.

- Advanced System Settings ➔ Environment Variables ➔ Edit JAVA_HOME ➔ Paste Variable Value 'C:\Program Files\Java\jdk1.8.0_211' ➔ OK ➔ OK.

- To Verify run Command Prompt or Power Shell and type the command:

Command Prompt Command:
$ echo %JAVA_HOME%

OR

Power Shell Command:
C:\> echo $env:JAVA_HOME

Output: 
C:\Program Files\Java\jdk1.8.0_211

➔ Java Installation in Linux:

1. Download Java at any location:

$ sudo yum install -y wget
$ sudo wget https://www.dropbox.com/s/lnabqwru5jgc30s/jdk-8u201-linux-x64.rpm

2. Install downloaded RPM:

$ sudo rpm -ivh jdk-8u171-linux-x64.rpm\?dl\=0

3. Verify the version of Java:

$ java -version

4. Configure JAVA_HOME environment variable:

$ export JAVA_HOME=/usr/java/jdk1.8.0_171-amd64
$ export PATH=$PATH:$JAVA_HOME

The path provided above with the command 'export <PATH>' will be disappeared when the system reboots. To make it permanent, we have to add the paths in the system-wide profile:

$ sudo vi /etc/profile.d/java.sh

#!/bin/bash
JAVA_HOME=/usr/java/jdk1.8.0_171-amd64/
PATH=$JAVA_HOME/bin:$PATH
export PATH JAVA_HOME
export CLASSPATH=.

:wq

5. Save and close the file and make it executable using command:

$ sudo chmod +x /etc/profile.d/java.sh

Now, set the environment variables permanently by running the following command:

$ source /etc/profile.d/java.sh

6. Verify Environment Variables:

$ echo $JAVA_HOME
$ echo $PATH

Step 3: Install Jenkins package and start the service:

Open below-mentioned link in browser:
https://pkg.jenkins.io/redhat-stable/

Right click on the latest version of Jenkins and copy link address, like I am using 'jenkins-2.176.1-1.1.noarch.rpm'. Open terminal and run the command:

$ sudo rpm -ivh https://pkg.jenkins.io/redhat-stable/jenkins-2.176.1-1.1.noarch.rpm

$ sudo service jenkins status
Jenkins is in Inactive state. To activate Jenkins run commands:

$ sudo service jenkins start
$ sudo systemctl enable jenkins.service

Now, Jenkins is in the active and running state and we enabled the service so that we do not perform this activity on every reboot of the Jenkins server.

Step 4: Run Jenkins in browser:

Copy public IP from GCP dashboard ➔ Paste it on browser followed by port 8080
e.g: <public-IP>:8080 or type 'localhost:8080'

Step 5: Unlock Jenkins:

As we try to access Jenkins on the browser, this will prompt to unlock Jenkins:

Unlock Jenkins
Fig: Unlock Jenkins
Copy the path provided in the screen and use 'cat' command to get the password. Copy that password from there and paste it in the browser and then click on 'Continue'. By doing this, we got access to Jenkins server. The browser screen is now asking to install Plugins. We can choose either 'Install suggested plugins' to install default plugins or we can choose 'Select plugins to install' if we want to customize them. 

Jenkins - Getting Started
Fig: Jenkins - Getting Started
After installation of plugins, this will prompt to create a username and password. Fill that form and click on Save and Continue. Jenkins server will now launch on this URL ➔ Save and Finish ➔ Start using Jenkins.

Now, we can see our Jenkins server's dashboard.

Jenkins Home Page
Fig: Jenkins Home Page

Step 6: Configure System:

Quiet Period: 0

Navigate to 'Artifactory' Section ➔ Add Artifactory Server ➔ Artifactory Server ID: artifactory ➔ URL: (provide your Artifactory Server URL) (e.g. http://1.2.3.4:8081/artifactory) ➔ username: admin (default username) ➔ password: password (default password) ➔ Click on 'Test Connection', this will communicate with the provided artifactory server with username and password and as a result it will show 'Found Artifactory <version>' ➔ Save.

Step 7: Global Tool Configuration:

Under section git > Git Name: Default > Path: git

Under section Maven > Maven Name: Maven 3.6.1 > Maven_HOME: /opt/apache-maven-3.6.1

Apply > Save.

Step 8: To use Maven projects in the future, we need to install Maven in Jenkins server:

$ sudo yum install -y wget

$ cd /opt

Copy Maven binaries from http://maven.apache.org/download.cgi

$ sudo wget http://apachemirror.wuchna.com/maven/maven-3/3.6.1/binaries/apache-maven-3.6.1-bin.tar.gz

$ sudo tar -xvf apache-maven-3.6.1-bin.tar.gz

Create environment variable for Maven: 

$ sudo vi /etc/profile.d/maven.sh

#!/bin/bash
MAVEN_HOME=/opt/apache-maven-3.6.1
PATH=$MAVEN_HOME/bin:$PATH
export PATH MAVEN_HOME
export CLASSPATH=.

$ source /etc/profile.d/maven.sh

Verify:
$ echo $MAVEN_HOME

Step 9: To use Git in the future, we need to install Git in Jenkins server:

$ sudo yum install -y git





No comments:

Post a Comment

Pages