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
- Log in to the AWS Management Console.
- Navigate to the EC2 Dashboard and click “Launch Instance.”
- Choose an Amazon Machine Image (AMI). For Jenkins, an Ubuntu Server AMI is recommended.
- Select an instance type. The t2.micro type is sufficient for small to medium workloads.
- Configure instance details as needed, ensuring you select a VPC and subnet.
- Add storage. The default settings are usually sufficient.
- Add tags for better resource management.
- Configure the security group to allow SSH (port 22) and HTTP (port 80).
- Review and launch the instance. Select your key pair for SSH access.
Step 2: Establishing an SSH Connection to Your Instance
- Open your terminal (Linux/macOS) or use an SSH client (Windows).
- 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:
- Update your package manager:
sudo apt update
- Install OpenJDK:
sudo apt install openjdk-11-jdk -y
- Verify the installation:
java -version
Step 4: Installing and Configuring Jenkins
- 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’
- Update your package manager:
sudo apt update
- Install Jenkins:
sudo apt install jenkins -y
- Start Jenkins:
sudo systemctl start jenkins
- Enable Jenkins to start at boot:
sudo systemctl enable jenkins
Step 5: Setting Up Your Security Group for Access
- In the AWS Management Console, go to the EC2 Dashboard.
- Select your instance and navigate to the “Security” tab.
- 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
- Open your web browser and navigate to http://your-instance-public-dns:8080.
- Unlock Jenkins using the initial administrator password:
sudo cat /var/lib/jenkins/secrets/initialAdminPassword
- Follow the on-screen instructions to complete the setup, including installing recommended plugins.
Step 7: Creating and Running Your First Jenkins Job
- From the Jenkins dashboard, click “New Item.”
- Enter a name for your job and select “Freestyle project.”
- Configure your job (e.g., add a source code repository build triggers).
- Save and click “Build Now” to run your job.
- 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.