DEV Community

Cover image for A Guide to Installing Jenkins, Configuring it and expose to outside world.
Subodh Bagde
Subodh Bagde

Posted on

A Guide to Installing Jenkins, Configuring it and expose to outside world.

What is Jenkins?

Jenkins is an open-source Java automation server used for software development lifecycle automation of repetitive operations. Being able to integrate with nearly all tools in the CI/CD pipeline with its many plugin support makes it a vital tool for developers and DevOps engineers.

AWS EC2 Instance

  • Go to AWS Console
  • Instances(running)
  • Launch instances

Install Jenkins

Pre-Requisites:

  • Java (JDK)

Run the below commands to install Java and Jenkins

Install Java


sudo apt update
sudo apt install openjdk-11-jre

Verify Java is Installed

java --version
Enter fullscreen mode Exit fullscreen mode

Now, you can proceed with installing Jenkins

curl -fsSL https://pkg.jenkins.io/debian/jenkins.io-2023.key | sudo tee \
  /usr/share/keyrings/jenkins-keyring.asc > /dev/null
echo deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc] \
  https://pkg.jenkins.io/debian binary/ | sudo tee \
  /etc/apt/sources.list.d/jenkins.list > /dev/null
sudo apt-get update
sudo apt-get install jenkins
Enter fullscreen mode Exit fullscreen mode

By default, Jenkins will not be accessible to the external world due to the inbound traffic restriction by AWS. Open port 8080 in the inbound traffic rules as show below.

Add inbound traffic rules as shown in the image:

f2

Login to Jenkins using the below URL:

http://:8080 [You can get the ec2-instance-public-ip-address from your AWS EC2 console page]

After you login to Jenkins,
- Run the command to copy the Jenkins Admin Password - sudo cat /var/lib/jenkins/secrets/initialAdminPassword
- Enter the Administrator password

f3

Click on Install suggested plugins

f4

Wait for the Jenkins to Install suggested plugins.

f5

Create First Admin User or Skip the step.

f6

Jenkins Installation is Successful. You can now starting using the Jenkins

f7

Install the Docker Pipeline plugin in Jenkins:

  • Log in to Jenkins.
  • Go to Manage Jenkins > Manage Plugins.
  • In the Available tab, search for "Docker Pipeline".
  • Select the plugin and click the Install button.
  • Restart Jenkins after the plugin is installed.

f9

Wait for the Jenkins to be restarted.

Docker Slave Configuration

Run the below command to Install Docker

sudo apt update
sudo apt install docker.io
Enter fullscreen mode Exit fullscreen mode

Grant Jenkins user and Ubuntu user permission to docker daemon.

sudo su - 
usermod -aG docker jenkins
usermod -aG docker ubuntu
systemctl restart docker
Enter fullscreen mode Exit fullscreen mode

You can run the below command to check if docker is up and running:

docker run hello-world
Enter fullscreen mode Exit fullscreen mode

f8

Once you are done with the above steps, it is better to restart Jenkins.

http://<ec2-instance-public-ip>:8080/restart
Enter fullscreen mode Exit fullscreen mode

The docker agent configuration is now successful.

You can also refer my GitHub Repo:

https://github.com/SubodhBagde/Jenkins-Demo-Pipeline/tree/main
Enter fullscreen mode Exit fullscreen mode

A simple Jenkins pipeline to verify if the docker agent configuration is working as expected.

Follow the steps to implement your first pipeline in Jenkins.

  • Click on the New Item tab on the left side of your Jenkins UI. Give a name and select Pipeline option and click on OK.

f10

  • Now configure the pipeline as shown below in the image.

f11

f12

  • Finally click on Build Now tab on the left to start the process.

f13

  • Here's the output, simply cick on the console output to view it.

f14

Multi Stage Multi Agent

Set up a multi stage jenkins pipeline where each stage is run on a unique agent. This is a very useful approach when you have multi language application
or application that has conflicting dependencies.

Steps involved in it are pretty much similar to the previous one.

  • You have to just replace the Script path my this folder name, as shown below.

f15

  • Run the following docker command to check whether the container has been build or not. You can see that once the execution is done the Jenkins application automatically deletes the container.
docker ps
Enter fullscreen mode Exit fullscreen mode

f16

The Multi Stage Multi Agent process is successful.

Top comments (1)

Collapse
 
illustrator43 profile image
Illustrations using sketchbook app

awesome tutorial