Setting Up Jenkins in AWS: A Step-by-Step Guide!!

Setting Up Jenkins in AWS: A Step-by-Step Guide!!

To set up Jenkins in an AWS, you can follow these steps:

  1. Launch an EC2 Instance: Start by launching an EC2 instance running Ubuntu in your desired AWS region. Choose an appropriate instance type based on your requirements.

  2. Configure Security Group: During the EC2 instance launch, configure a security group to allow incoming traffic on port 8080 (or any other port you choose for Jenkins) from your IP address or a specific range of IP addresses.

  3. Connect to the EC2 Instance: Once the instance is running, connect to it using SSH. You can use an SSH client like PuTTY (Windows) or the terminal (macOS/Linux).

  4. Update Packages: Run the following command to update the package lists for upgrades and new installations:

     sudo apt update
    
  5. Install Java Development Kit (JDK): Jenkins requires Java to run. Install OpenJDK using the following command:

     sudo apt install openjdk-11-jre
    
  6. Install Jenkins: Add the Jenkins repository key to the system using the following commands:

     curl -fsSL https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key | sudo tee \
       /usr/share/keyrings/jenkins-keyring.asc > /dev/null
    
  7. Then add the Jenkins repository to the package sources:

     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
    
  8. Update the package lists and install Jenkins:

     sudo apt-get update
     sudo apt-get install jenkins
    
  9. Start Jenkins: The Jenkins service should start automatically after installation. If it's not running, start it with the following command:

     sudo systemctl start jenkins
    

    we’ll use the status command to verify that Jenkins started successfully:

     sudo systemctl status jenkins
    

  10. Allow Jenkins Access: Configure the security group associated with your EC2 instance to allow incoming traffic on the Jenkins port (e.g. 8080) from anywhere or your desired IP range.

  11. Access Jenkins Web Interface: Open a web browser and enter the public IP address or DNS name of your EC2 instance followed by the Jenkins port (e.g. http://<your_public_ip>:8080). You should see the Jenkins setup wizard.

  12. Retrieve Jenkins Initial Administrator Password: To set up Jenkins, you need to provide the initial administrator password. SSH into your EC2 instance and use the following command to get the password:

    sudo cat /var/lib/jenkins/secrets/initialAdminPassword
    ##Copy the password and paste it into the Jenkins setup wizard.
    
  13. Complete Jenkins Setup: In next blog we'll see instructions to complete the initial setup, including installing suggested plugins and creating an admin user.

That's it! You should now have Jenkins set up in your AWS.

~Puneet 🙃