Table of Contents
Introduction
Jenkins stands as an invaluable open-source automation server, streamlining the repetitive technical tasks integral to continuous integration and software delivery processes. As a Java-based solution, Jenkins can be effortlessly installed on Ubuntu either through packages or by deploying its web application archive (WAR) file—a comprehensive assembly of files necessary for executing a complete web application on a server.
This Bash script automates the installation of Jenkins, a popular automation server used for continuous integration and continuous delivery (CI/CD) pipelines. By running this script, you can quickly set up Jenkins on a Debian-based system, such as Ubuntu, saving time and ensuring a consistent installation process.
The script first updates the system's package repository and then adds the Jenkins repository key and repository to the system's sources list. It then installs Jenkins, along with the required dependencies like fontconfig and OpenJDK 17. After installation, the script enables the Jenkins service and displays the Jenkins URL along with the initial password needed to unlock Jenkins for the first time.
Installing
devops@Techvoot:~/scripts$ cat jenkinsh-setup.sh
#!/bin/bash
sudo apt update
sudo apt upgrade -y
# Add Jenkins repository key
sudo wget -O /usr/share/keyrings/jenkins-keyring.asc https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key
# Add Jenkins repository to sources 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
# Update package lists
sudo apt-get update
# Install Jenkins
sudo apt-get install -y jenkins
# Install fontconfig and OpenJDK 17
sudo apt-get install -y fontconfig openjdk-17-jre
# Check Java version
java -version
# Enable Jenkins service
sudo systemctl enable jenkins
# Fetch public IP address using curl
public_ip=$(curl -s https://api.ipify.org)
# Print the fetched IP address along with port 8080
echo "Your Application is running on: $public_ip:8080"
echo "Please use the following initial password to unlock Jenkins:"
sudo cat /var/lib/jenkins/secrets/initialAdminPassword
echo "script is running successfully……!!😀"
- Setting the execute permission allows you to run the script with a simple command, which can be more convenient than specifying the interpreter each time.
-
Security: By setting execute permissions, you control who can run the script. You can restrict execution to certain users or groups.
$ chmod +x jenkinsh-setup.sh
-
how to run script
$ sh jenkinsh-setup.sh
Conclusion
Automating the installation of Jenkins with this Bash script provides a straightforward and efficient way to set up Jenkins on a Debian-based system. By automating the installation process, users can save time and ensure a consistent setup across multiple environments. This script streamlines the installation of Jenkins, making it easier for users to leverage Jenkins for their continuous integration and continuous delivery (CI/CD) pipelines.