Tanmay Shukla
Posted on March 14, 2023
Introduction
Jenkins is a free and open-source automation server. It helps automate the parts of software development related to building, testing, and deploying, facilitating continuous integration and continuous delivery.
Installation of Jenkins
There are multiple ways to install jenkins
1. Jenkins On Ubuntu:
- First, install java:
sudo apt-get update
sudo apt-get -y upgrade
sudo apt search openjdk
sudo apt install openjdk-11-jdk
java -version
- Now go to Jenkins download and follow instructions. Then run:
sudo systemctl status jenkins
sudo systemctl enable jenkins
sudo systemctl start jenkins
- Finally go to:
http://ip_address_or_domain:8080
- Run this to get initial password
sudo cat /var/lib/jenkins/secrets/initialAdminPassword
- Select like below:
- Create a first admin user
- Now your jenkins is ready to use, Welcome to the world of jenkins: Note : Make sure you have enabled 8080 port(by enabling custom tcp/udp as 8080 inside inbound rules in your security group if using EC2)
2. On Docker container:
- Install docker:
sudo apt-get update
sudo apt-get -y upgrade
sudo install docker.io
- Now to download an jenkins image and run it as docker command we need to run the following command
docker run -p 8080:8080 -p 50000:50000 -d -v jenkins_home:/var/jenkins_home
- 8080:8080 --> specify the port(bind the host(server) port 8080 to jenkins port 8080)
-
50000:50000 --> port where jenkins master and slave will communicate(as jenkins can be build and started as a cluster). If we have large workloads that you are running with the jenkins, so this port is where communication between master and worker node is happening.
-
-d
: To run container in detached mode(background) -
-v
: To mount the volumes jenkins_home -
jenkins/jenkins:lts
: Official docker image for jenkins - Now Check our jenkins container with
docker ps
: - Finally, please go to:
http://ip_address_or_domain:8080
- After opening the Jenkins dashboard, follow the above steps.
- Run docker exec -it ` bash --> To run a command in a running container(i.e. login as jenkins user)
- Run `docker volume inspect jenkins_home --> To get info about our created volume.
-
3. On Amazon Linux 2/ CentOS
- First install java:
sudo yum update -y sudo yum install java-1.8.0-openjdk
- Now download latest jenkins package:
sudo wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat/jenkins.repo
- Import a key file from Jenkins-CI to enable installation from the package:
sudo rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io.key
- Install Jenkins
sudo yum install jenkins -y
- Enable the Jenkins service to start at boot:
sudo systemctl enable jenkins
sudo systemctl start jenkins
sudo systemctl status jenkins
✨✨Note: For CentOS make sure to configure firewall as, Jenkins service uses port 8080 to communicate. If you’re using the default firewalld service, enter the following commands to allow access:
sudo firewall-cmd ––permanent ––zone=public ––add-port=8080/tcp
sudo firewall-cmd ––reload
- Open a web browser, and enter the following URL:
http://ip_address_or_domain:8080
4. Jenkins on Windows 10:
While it is recommended that you install jenkins controller on linux based server as windows has some complication like locking file sysytem semantics, but we can also install it on our local Windows machine also.
Just Go through these videos to get up & running:
- Install jenkins on Windows server 2022
- Install jenkins on local windows 10
- Blog on jenkins on Windows 10
5. Running jenkins as a WAR(Web Application Resource or Archive) file
- Before installing jenkins make sure you have following
- Running jenkins using war file is platform/OS independent.
- Only requires that JRE or JDK be insatlled on target.
- Java 8 and 11 are supported only.
- Go to jenkins download page and copy the link of Generic Java package(.war) file.
- Then use
wget <jenkins.war link>
to download the war file inside your home directory. - Now all you need to run jenkins is invoke java by running:
java -jar jenkins.war
- Finally go to
localhost or <your_ip_address>:8080
as jenkins by default runs on port 8080. Hence your jenkins is up and running.
Note:
We can do this other way also by installing tomcat and then deploy the war file. As eventually when we run java application on our servers. We require tomcat (Apache Tomcat is a web server and servlet container that is used to deploy and serve Java web applications)
sudo apt install openjdk-11-jdk
sudo apt install wget
- Install tomcat 9 with
wget https://archive.apache.org/dist/tomcat/tomcat-9/v9.0.0.M10/bin/apache-tomcat-9.0.0.M10.tar.gz
- Extract the files
tar xzf apache-tomat-9.0.0.M10.tar.gz
- Extract the files
- To make it simple we will move this extracted file to a new directory Tomcat9 using the mv command and to do that I will execute the following command:
mv apache-tomcat-9.0.0.M10 tomcat9
- Our next step is to provide a username and password for Apache Tomcat --->
vim /home/edureka/tomcat9/conf/tomcat-users.xml
- Now replace the tomcat-users.xml content with following. This is to create tomcat users
<?xml version='1.0' encoding='utf-8'?>
<tomcat-users>
<role rolename="manager-gui"/>
<role rolename="manager-script"/>
<role rolename="manager-jmx"/>
<role rolename="manager-jmx"/>
<role rolename="admin-gui"/>
<role rolename="admin-script"/>
<user username="user1" password="password1" roles="manager-gui,manager-script,manager-jmx,manager-status,admin-gui,admin-script"/>
</tomcat-users>
In the above code, as you can see that I have defined several roles and for all these roles I have given one single username called user1
and password i.e. password
. If you want to assign different username and password for different roles you can do that as well.
Now save it and close the file to go back to the terminal.
- We need to start Apache Tomcat now, but before that I will change my directory to Tomcat9 by executing the below command:
cd tomcat9
- To start Tomcat use the below command:
./bin/startup.sh
- Now we need to download Jenkins war File:
JENKINS FUNDAMENTALS
- Roles in jenkins : In Jenkins we have two kinds of Roles.
- We create jobs in jenkins to Automate app workflow
- Build Tools: Maven(java app), Gradle, NPM(nodejs app)
- Create simple freestyle jobs and Configure Git Repository.
- Run Tests and build java application
Posted on March 14, 2023
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.