Introduction: Understanding Jenkins and its Role in CI/CD

Jenkins is an open-source automation server that facilitates continuous integration and continuous delivery (CI/CD) of software projects. It helps automate the parts of software development related to building, testing, and deploying, allowing developers to focus on writing code. Jenkins supports various tools and technologies, making it a cornerstone in modern DevOps practices.

Prerequisites: An Overview of What You’ll Need

Before diving into the installation process, ensure you have the following prerequisites:

  • An AWS account with the necessary permissions to create EC2 instances.
  • Basic knowledge of AWS EC2 and SSH.
  • A key pair for SSH access to your instance.
  • Familiarity with basic Linux commands.

Step 1: Launching Your EC2 Instance on AWS

  1. Log in to the AWS Management Console.
  2. Navigate to the EC2 Dashboard and click “Launch Instance.”
  3. Choose an Amazon Machine Image (AMI). For Jenkins, an Ubuntu Server AMI is recommended.
  4. Select an instance type. The t2.micro type is sufficient for small to medium workloads.
  5. Configure instance details as needed, ensuring you select a VPC and subnet.
  6. Add storage. The default settings are usually sufficient.
  7. Add tags for better resource management.
  8. Configure the security group to allow SSH (port 22) and HTTP (port 80).
  9. Review and launch the instance. Select your key pair for SSH access.

Step 2: Establishing an SSH Connection to Your Instance

  1. Open your terminal (Linux/macOS) or use an SSH client (Windows).
  1. Connect to your instance using the following command:

    ssh -i /path/to/your-key-pair.pem ubuntu@your-instance-public-dns

Step 3: Getting Java Up and Running on Your Instance

Jenkins requires Java to run. Install Java using the following commands:

  1. Update your package manager:

    sudo apt update
  1. Install OpenJDK:
    sudo apt install openjdk-11-jdk -y
  1. Verify the installation:
    java -version

Step 4: Installing and Configuring Jenkins

  1. Add the Jenkins repository to your system:
    wget -q -O – https://pkg.jenkins.io/debian/jenkins.io.key | sudo apt-key add –

sudo sh -c ‘echo deb http://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list’

  1. Update your package manager:
    sudo apt update
  1. Install Jenkins:
    sudo apt install jenkins -y
  1. Start Jenkins:
    sudo systemctl start jenkins
  1. Enable Jenkins to start at boot:
    sudo systemctl enable jenkins

Step 5: Setting Up Your Security Group for Access

  1. In the AWS Management Console, go to the EC2 Dashboard.
  2. Select your instance and navigate to the “Security” tab.
  3. Edit the security group to allow inbound traffic on port 8080 for Jenkins:
    • Type: Custom TCP Rule
    • Protocol: TCP
    • Port Range: 8080
    • Source: Anywhere (or restricted to specific IP ranges)

Step 6: Accessing Your Jenkins Web Interface

  1. Open your web browser and navigate to http://your-instance-public-dns:8080.
  1. Unlock Jenkins using the initial administrator password:
    sudo cat /var/lib/jenkins/secrets/initialAdminPassword
  1. Follow the on-screen instructions to complete the setup, including installing recommended plugins.

Step 7: Creating and Running Your First Jenkins Job

  1. From the Jenkins dashboard, click “New Item.”
  2. Enter a name for your job and select “Freestyle project.”
  3. Configure your job (e.g., add a source code repository build triggers).
  4. Save and click “Build Now” to run your job.
  5. Monitor the build progress and review the output in the “Console Output” section.

Conclusion: Exploring Jenkins Further and Next Steps

Congratulations on setting up Jenkins on AWS EC2! With Jenkins running, you can explore more advanced features, such as integrating with other tools, setting up pipelines, and scaling your CI/CD processes. Jenkins provides extensive documentation and a vibrant community to help you.

References

Set Up a Jenkins Build Server

Installing the plugin