Setting Up Jenkins on EC2


Today, I embarked on setting up Jenkins on an EC2 instance. It was an exciting journey filled with learning and hands-on experience. Here’s a step-by-step rundown of the process and some useful insights I gathered along the way.

Step-by-Step Guide to Installing Jenkins on EC2

  1. Update Your Packages: First, it’s always a good idea to ensure all your packages are up to date.

     sudo apt update
    
  2. Install Java: Jenkins requires Java to run, so the next step is to install OpenJDK.

     sudo apt install openjdk-11-jre
     java -version
    

    This verifies the installation and checks the Java version.

  3. Add Jenkins Key and Repository: We need to add the Jenkins key to the system and then add the Jenkins repository to the sources list.

     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
    
  4. Update Packages and Install Jenkins: After adding the repository, update your package list and install Jenkins.

     sudo apt-get update
     sudo apt-get install jenkins
    
  5. Access Jenkins Initial Admin Password: To set up Jenkins, you need the initial admin password, which can be found in the following file:

     sudo cat /var/lib/jenkins/secrets/initialAdminPassword
    
  6. Install Docker (Optional): I also installed Docker to explore containerized builds and deployments with Jenkins.

     sudo apt install docker.io
    
  7. Verify Jenkins is Running: Switch to the Jenkins user and check if the Jenkins service is running.

     sudo su - jenkins
     ps -ef | grep jenkins
     exit
    
  8. Monitor System Performance: I used htop to monitor the system performance and ensure everything was running smoothly.

     htop
    

Insights and Learnings:

  • Importance of Java for Jenkins: Ensure you have the correct version of Java installed as Jenkins heavily relies on it.

  • Adding Repositories and Keys: Using wget and tee commands to add repositories and keys is straightforward and essential for package installations.

  • Monitoring and Performance: Tools like htop are invaluable for keeping an eye on system resources, especially when running resource-intensive applications like Jenkins.

Conclusion:

Setting up Jenkins on an EC2 instance is a great way to get hands-on with continuous integration and delivery. It’s a powerful tool that, once set up, can significantly streamline your development workflow.

Feel free to reach out if you have any questions or need further assistance!


Hope this helps and happy coding!