How To Install Jenkins Using Base Script On Ubuntu 20.04

How To Install Jenkins Using Base Script On Ubuntu 20.04

Dhaval Baldha

07 May 2024

3 MINUTES READ

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.

FAQ

This Bash script automates the installation of Jenkins on Ubuntu 20.04, simplifying the setup process for continuous integration and delivery pipelines.

The script updates the system's package repository, adds the Jenkins repository key and repository to the sources list, installs Jenkins and its dependencies, enables the Jenkins service, and displays the Jenkins URL and initial password.

Yes, this script is designed for Debian-based systems like Ubuntu. It should work on other distributions with minimal modifications.

Automating the installation process saves time and ensures consistency across multiple environments. Users can quickly set up Jenkins for their CI/CD pipelines without manual intervention.

Dhaval Baldha
Dhaval Baldha

Co-founder

Dhaval is a visionary leader driving technological innovation and excellence. With a keen strategic mindset and deep industry expertise, he propels the company towards new heights. His leadership and passion for technology make him a cornerstone of Techvoot Solutions' success.

Linkedin
Hire Skilled Developer

*Please fill all the required fields

Get our Newsletter

Customized solutions for your projects

*Please fill all the required fields