Jenkins is a popular open-source automation server that helps streamline your software development and deployment pipelines. In this guide, we’ll walk through setting up Jenkins on AWS, step by step.
Prerequisites
AWS Account: Ensure you have access to the AWS Management Console.
SSH Key Pair: Generate a key pair or use an existing one for EC2 instance access.
Security Group Rules: Allow HTTP (port 8080) and SSH (port 22) in your security group.
Basic AWS CLI Knowledge (Optional): If you want to automate steps.
Step 1: Launch an EC2 Instance
Navigate to EC2 Dashboard:
- Go to the AWS Management Console > EC2 > Instances > Launch Instances.
Choose AMI:
- Select Ubuntu Server 20.04 LTS (free-tier eligible).
Instance Type:
- Choose t2.micro (free-tier eligible).
Configure Instance Details:
Leave default settings or customize as needed.
Ensure the instance is in a public subnet.
Add Storage:
- Default storage (8 GB) is sufficient for Jenkins.
Configure Security Group:
Add the following inbound rules:
SSH: Port 22, Source: My IP.
Custom TCP Rule: Port 8080, Source: 0.0.0.0/0 (for Jenkins web access).
Review and Launch:
Review your settings and click Launch.
Select your key pair or create a new one, then launch the instance.
Step 2: Connect to the EC2 Instance
Open your terminal or SSH client.
Run the following command to connect:
ssh -i "your-key.pem" ubuntu@<EC2_PUBLIC_IP>
Replace
<EC2_PUBLIC_IP>
with the public IP of your instance.
Step 3: Install Jenkins
Update System Packages:
sudo apt update && sudo apt upgrade -y
Install Java (Required for Jenkins):
sudo apt install -y openjdk-11-jdk
Add Jenkins Repository:
curl -fsSL https://pkg.jenkins.io/debian-stable/jenkins.io.key | sudo tee \ /usr/share/keyrings/jenkins-keyring.asc > /dev/null 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
Install Jenkins:
sudo apt update sudo apt install -y jenkins
Start Jenkins Service:
sudo systemctl start jenkins sudo systemctl enable jenkins
Step 4: Access Jenkins Web Interface
Open a web browser and navigate to:
http://<EC2_PUBLIC_IP>:8080
Unlock Jenkins:
Find the initial admin password:
sudo cat /var/lib/jenkins/secrets/initialAdminPassword
Copy the password and paste it into the web interface.
Set Up Jenkins:
Install recommended plugins.
Create an admin user.
Configure instance URL (use the public IP).
Step 5: Secure Your Jenkins
Enable Security:
Use IAM roles for EC2 to manage AWS resources securely.
Configure HTTPS using a reverse proxy (e.g., Nginx or Apache).
Backup Configurations:
- Use plugins like ThinBackup for periodic Jenkins backups.
Step 6: Install Essential Plugins
Go to Manage Jenkins > Manage Plugins.
Recommended plugins:
Git: For SCM integration.
Pipeline: To create Jenkins pipelines.
Docker: If you use Docker for builds.
Credentials: To manage secrets.
Step 7: Create Your First Job
Click New Item in Jenkins.
Enter a name, select Freestyle project, and configure the project settings.
Add build steps, such as running shell commands or pulling from a Git repository.
Step 8: Automate Jenkins with AWS (Optional)
IAM Role for EC2 Instance: Attach an IAM role with necessary permissions to access AWS resources.
S3 for Backup: Configure backups to S3 using AWS CLI or plugins.
Conclusion
You now have a fully functional Jenkins instance running on AWS, ready to automate your CI/CD pipelines. Jenkins provides extensive customization with plugins and can integrate seamlessly with tools like Docker, Kubernetes, and AWS services.
Start building pipelines and automate your workflows for enhanced productivity!