Steps to install and configure Jenkins (Built-in node and Slave) CI/CD on AWS EC2 instances
Charles Ranaweera
AWS | Azure | SQL | Fortinet | PMP | ITIL | ISO 27001 | Certified Product Owner
I've included the minimum hardware requirements below as per official Jenkins documentation.
However, I performed better with AWS EC2 T2Micro Large (Ubuntu).
Installation of Java
sudo apt update
sudo apt install fontconfig openjdk-17-jre
java -version
openjdk version "17.0.14" 2025-01-21
OpenJDK Runtime Environment (build 17.0.14+7-Ubuntu-124.04)
OpenJDK 64-Bit Server VM (build 17.0.14+7-Ubuntu-124.04, mixed mode, sharing)
Installation of Jenkins
sudo wget -O /usr/share/keyrings/jenkins-keyring.asc \ https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key
echo "deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc]" \ https://pkg.jenkins.io/debian-stable binary/ | sudo tee \ /etc/apt/sources.list.d/jenkins.list > /dev/null
sudo apt-get update
sudo apt-get install jenkins
Start Jenkins
You can enable the Jenkins service to start at boot with the command:
sudo systemctl enable jenkins
You can start the Jenkins service with the command:
sudo systemctl start jenkins
You can check the status of the Jenkins service using the command:
sudo systemctl status jenkins
If everything has been set up correctly, you should see an output like this:
jenkins.service - Jenkins Continuous Integration Server
Loaded: loaded (/usr/lib/systemd/system/jenkins.service; enabled; preset: enabled)
Active: active (running) since Tue 2025-02-18 23:23:39 UTC; 5min ago
Main PID: 4184 (java)
Tasks: 45 (limit: 9507)
Memory: 552.1M (peak: 1.0G)
CPU: 19.871s
CGroup: /system.slice/jenkins.service
└─4184 /usr/bin/java -Djava.awt.headless=true -jar /usr/share/java/jenkins.war --webroot=/var/cache/jenkins/war --httpPort=8080
Feb 18 23:23:33 ip-172-31-23-0 jenkins[4184]: e12d8b46cd0b4a86b88feb
Getting Started with Jenkins on Browser
Type HTTP://publicip:8080 on your browser to land on the following page
You can find the Administrator password in /var/lib/jenkins/secrets/initialAdminPassword
Install Plugins
Grab a coffee ! :)???
Let's go with suggested plugins. This will take a while depending on the speed of the network.
After completion, you should see this
You can create an admin user (recommended)
Let's add a slave node. The information below demonstrates how you can add nodes.
Installation of Java to the Jenkins slave node
sudo apt update
sudo apt install fontconfig openjdk-17-jre
java -version
openjdk version "17.0.14" 2025-01-21
OpenJDK Runtime Environment (build 17.0.14+7-Ubuntu-124.04)
OpenJDK 64-Bit Server VM (build 17.0.14+7-Ubuntu-124.04, mixed mode, sharing)
create ssh key
ubuntu@ip-172-31-35-47:~$ sudo su
root@ip-172-31-35-47:/home/ubuntu# mkdir jenkins-slave
root@ip-172-31-35-47:/home/ubuntu# chmod 755 jenkins-slave/
root@ip-172-31-35-47:/home/ubuntu# ssh-keygen
Generating public/private ed25519 key pair.
Enter file in which to save the key (/root/.ssh/id_ed25519):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_ed25519
You can use ssh keys to establish connectivity with the main node and slave in your Jenkin cluster.
Now install plugins as required.
Select Maven, Sonarcube, JKD, Docker, OWASP as required
Create our first Jenkin job
A sample Declarative Pipeline.
Build stages - Pipeline
This can be extended from a freestyle project to a Pipeline or multibranch pipeline as per your business requirement. CI/CD stages can be introduced as per your requirement to compile, inspect, build and deploy your codes.
You can use the below source code to test your own.
Last update on 21/02/2025 by Charles Ranaweera
#AWS #Jenkins #OWASP #SonarQube #Docker #Maven #DevOps #CI/CD #InfrastructureAsCode #CloudComputing