Jenkins and its Set Up
- mohdmyyusuf
- Aug 1, 2022
- 4 min read
Updated: Aug 13, 2022
CI/CD it is a practice which help in a ready to deploy code creation.
Jenkins is an open source continuous integration server written in Java for orchestrating a chain of actions to achieve the continuous integration process in automated manner. Jenkins supports the complete software development life cycle like building, testing, deploying etc. In this way it helps in a fast delivery. jenkins follow a master slave architecture, master node works like a controller and slave nodes will work as execution nodes. Master node controls the load
distribution on slave nodes. The slave nodes don't need jenkins installed on them, only required java version should be available there.
Jenkins setup on Windows:
Go to jenkins.io/download/ and move to LTS(long term support).
Donload Jenkins Generic Java package (.war) file as we want to run jenkins as a service on Windows.
Copy the downloaded war in some folder.
Open the cmd in that folder and type the command: java -jar jenkins.war --httpPort==9090 jenkins will start on port 9090.
Now type {your machine ip}:port[9090], you will be navigated to jenkins very first landing page.
You will see the path of initialAdminPassword on it, move to the path and copy the initialAdminPassword from there.
Enter the initialAdminPassword in the password field.
Now jenkins will ask to install some plugins, select "Install suggested plugins" and wait for all plugins to be downloaded.
Now create the admin user to logon the jenkins portal.
How to setup Jenkins on Tomcat server:
Download Tomcat and unzip it, then put it in some location.
Copy and paste the jenkins.war file into tomcat/webapps folder.
Then go to tomcat\bin and open cmd there.
Type command “chmod +x *.sh” to make all .sh files to be executable.
Then type command “./startup.sh” to start tomcat server.
Now type localhost:8080 into a browser and check if tomcat has been started or not.
Now type localhost:8080/jenkins in the same browser window.
Jenkins installation on VM:
Prerequisite: 256 GB RAM, 1 GB external disk, Java 8 or 11, All OSs
Steps:
Create an account in Digital Ocean.
Then click "create a droplet"
Select the VM, you want to create.
After the machine is created you can give it a name and security password.
Then you will have a public IP.
Copy the public IP to create a SSL connection with your Jenkins server.
Now we have a VM with us. If it is a linux machine, we need putty or MOBAXTERM to make SSH connection with it. Open terminal and type the command
ssh root@[public IP of VM]. The name of the VM will be displayed in terminal like root@"vm name":-# [space to type command]. Now type set of commands to
install Java on the VM, run the command:
sudo apt-get -y install openjdk-8-jdk openjdk-8-jreThen check installation using java -version.
Set the environment variables, run the command:
cat >> /etc/environment <<EOL
JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
JRE_HOME=/usr/lib/jvm/java-8-openjdk-amd64/jre
EOLNow add the repository key to the system, run the command:
wget -q -O - https://pkg.jenkins.io/debian-stable/jenkins.io.key | sudo apt-key add - Then, append the Debian package repository address to the server’s sources.list:
sudo sh -c 'echo deb http://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list'Update System packages:
sudo apt updateNow install Jenkins and its dependencies:
sudo apt -y install jenkinsStart Jenkins using systemctl:
sudo systemctl start jenkinsNow get Service Status ie the status of the jenkins server:
sudo systemctl status jenkinsAfter that enable Jenkins Service so that even after the VM is restarted, we don't need to restart the jenkins server again and again. It will automatically set the jenkins
up, type the command:
sudo systemctl enable jenkinsNow the Jenkins is ready to be accessed on your local machine. Open any brwoser and type [IP of vm]:8080 The jenkins startup page will be opened enter the first secret key. Use the cat command to display the password:
sudo cat /var/lib/jenkins/secrets/initialAdminPasswordAnd then you are navigated to jenkins plugin installation page, select Install recommended. Then create the admin user. Now you are all set to use jenkins.
Jenkins installation on Azure Windows vm:
The steps include creation of MS Azure VM and setup of Jenkins on it. So we will create a VM first and then the jenkins setup.
VM Creation and connecting to it from local machine:
Logon the MS Azure portal and create a VM there by clicking create new resource > create VM.
Generate new Key at the last step to create a vm, it asks to download the key(a .pem file) and create resource and then wait for the VM to be created/deployed. Give the execute permission to the file(the downloaded .pem file) which has been downloaded while creation of vmrun the command:
chmod 700 (the .pem file path)Now after the vm is deployed completely, open it. Then click on "Connect" option. The public ip of the vm is displayed in the box "Run the example command below to connect to vm": ssh -i <path of private key> azureuser@<public ip of vm>. Then open cmd on your local machine and type the command:
ssh -i <path of private key> azureuser@<public ip of vm>It will ask if you want to connect to the vm, type yes. Now go to the vm in Azure portal and move to Networking and see the inbound port rules. Click Add inbound port rule button, give it any name say port_8080, give port port number(8080) in Destination port ranges field. Select the protocol as TCP select Action = allow and priority = 100 and click add button. It will take some time to create and open the port 8080.
Now lets install the jenkins in the vm.
Run the command in cmd:
sudo su - (it will navigate you to the root of the vm you will see root@vm_name in command prompt).We need java for jenkins so first run the command:
apt update, it will update all system packages.Now run the command and let the process be completed:
apt install openjdk-8-jdk or apt install openjdk-11-jre-headless, After that add the repository key to the system, run the command:
wget -q -O - https://pkg.jenkins.io/debian-stable/jenkins.io.key | sudo apt-key add - Then, append the Debian package repository address to the server’s sources.list run the command :
sudo sh -c 'echo deb http://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list'Update System packages again by running the command sudo apt update
Now install Jenkins and its dependencies, type the command:
sudo apt -y install jenkinsStart Jenkins using systemctl:
sudo systemctl start jenkinsNow get Service Status ie the status of the jenkins server:
sudo systemctl status jenkinsNow check on which port the jenkins is running, type the command:
ps -ef | grep jenkinsNow type the command in browser:
[IP of vm]:port_number.
Comments