Introduction:
Jenkins is a widely used open-source automation server that allows developers to automate various aspects of their software development workflow. By installing Jenkins on an AWS EC2 instance, you can easily set up a powerful continuous integration and continuous delivery (CI/CD) pipeline for your projects.
In this blog post, we will guide you through the step-by-step process of downloading, installing, and configuring Jenkins on various platforms.
Debian/Ubuntu:
Prerequisites:
Before proceeding with the Jenkins installation, ensure that you have the following prerequisites:
- An Ubuntu-based machine (e.g., Ubuntu 18.04 or Ubuntu 20.04)
- Sufficient permissions to install software on the machine.
- JDK 11 or higher
-
Step 1: Update Ubuntu Package Lists
-
-
- Open a terminal on your Ubuntu machine.
- Update the default Ubuntu package lists to prepare for upgrades.
-
#sudo apt-get update
Step 2: Install JDK 11
-
-
- Install JDK 11 using the following command:
-
#sudo apt-get install openjdk-11-jdk
-
-
- After installation, verify that Java has been installed successfully by running the following command:
-
#java -version
-
-
- You should see the Java version details displayed on the terminal, indicating that Java has been installed correctly.
-
Step 3: Add Jenkins Repository
-
-
- Instead of installing Jenkins from the usual Ubuntu repository, it is advised to use the project-maintained repository.
- The Jenkins version in the default Ubuntu repository might not be the most recent version, in which case it might not include the newest features and bug patches.
-
-
-
- To add the Jenkins repository to your Ubuntu system, follow the procedures listed below.
-
Import the GPG key used to verify the Jenkins repository package integrity. The following command will import the key without producing any output:
#curl -fsSL https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key | sudo tee /usr/share/keyrings/jenkins-keyring.asc > /dev/null
Add the Jenkins software repository and supply the authentication key to the source list:
#
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
After setting up the prerequisites, follow the steps below to install Jenkins on Ubuntu:
-
-
- Update the system repository one more time. Updating refreshes the cache and makes the system aware of the new Jenkins repository.
-
#sudo apt update
-
-
- Install Jenkins by running:
-
#sudo apt install jenkins -y
During the installation, you will be prompted to confirm the action. Press,
Y
and then pressEnter
to continue. Wait for the download and installation to complete.Start the Jenkins service using the following command:
sudo systemctl start jenkins
Enable Jenkins to start automatically on system boot:
sudo systemctl enable jenkins
To check if Jenkins is installed and running, run the following command:
sudo systemctl status jenkins
A bright green entry labeled
active (running)
should appear in the output, indicating that the service is running.-
-
- Access Jenkins Web Interface
-
Note: Modify the Firewall to Allow Jenkins
Login to the AWS Console
In your Jenkins master instance go to the security group and allow port 8080.-
-
- Jenkins is now running on your Ubuntu machine. You can access its web interface by navigating to “http://your_server_ip_or_domain:8080″ using your web browser.
- On the Jenkins web interface, you will be prompted to enter an initial admin password.
- To retrieve the password, use the following command:
-
Now, the screen presents the option of installing suggested plugins or selecting specific plugins:
-
-
- select the suggested plugins.
- Wait for the download and installation the suggested plugins.
-
After the installation of plugins, it’s time to create an admin account to login to Jenkins:
-
-
- Fill in the details click on the save and continue.
- Jenkins dashboard.
-
Linux (RHEL, Amazon Linux)
Prerequisites:
Before you start, ensure you have the following prerequisites:
-
-
- An AWS account with access to EC2 instances
- An EC2 instance running a supported Amazon Linux or Amazon Linux 2 AMI
- Java 11 or higher installed on your EC2 instance
-
Step 1: Update Software Packages
-
-
- SSH into your EC2 instance.
- Update the software packages to ensure your system is up to date.
-
sudo yum update -y
Step 2: Add Jenkins Repository
-
-
- Add the Jenkins repository to your system by running the following command.
-
#sudo wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repo
Step 3: Import Jenkins-CI Key
-
-
- Import the Jenkins-CI key to enable installation from the package.
-
#sudo rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io-2023.key
Step 4: Install Jenkins
-
-
- Upgrade the system packages.
-
#sudo yum upgrade -y
-
-
- Install Java (Amazon Linux 2).
-
#sudo amazon-linux-extras install java-openjdk11 -y
-
-
- Install Jenkins.
-
#sudo yum install jenkins -y
Step 5: Enable and Start Jenkins
-
-
- Enable the Jenkins service to start at boot.
-
#sudo systemctl enable jenkins
-
-
- Start Jenkins as a service.
-
sudo systemctl start jenkins
-
-
- Check the status of the Jenkins service to ensure it’s running.
-
sudo systemctl status jenkins
Step 6: Access Jenkins Web Interface
Note: Modify the Firewall to Allow Jenkins
Login to the AWS Console
In your Jenkins master instance go to the security group and allow port 8080.-
-
- Jenkins is now running on your Linux machine.
- You can access its web interface by navigating to “http://your_server_ip_or_domain:8080” using your web browser.
- On the Jenkins web interface, you will be prompted to enter an initial admin password.
- To retrieve the password, use the following command:
-
#
sudo cat /var/lib/jenkins/secrets/initialAdminPassword
-
-
- Copy the password from the terminal and paste it into the “Administrator password” field and click on continue.
-
Now, the screen presents the option of installing suggested plugins or selecting specific plugins:
-
-
- select the suggested plugins.
- Wait for the download and installation of the suggested plugins.
-
After the installation of plugins, it’s time to create an admin account to login to Jenkins:
-
-
- Fill in the details click on save and continue.
Jenkins dashboard.
- Fill in the details click on save and continue.
-
Jenkins is now ready to automate your CI/CD pipelines and streamline your software development processes.
Conclusion:
By using the latest Jenkins version, you can take full advantage of its features and enhancements. Enjoy the power of Jenkins and accelerate your software delivery with its wide range of capabilities. Happy automating!
-