Launch Jenkins on Amazon Linux 2 and Build Your First Pipeline
In the previous post, we covered what Jenkins is and how it fits into a CI/CD pipeline. Now it is time to get Jenkins actually running on a server. We will install it on an Amazon Linux 2 EC2 instance, access the dashboard for the first time, and create a simple job to make sure everything works.

Before You Start: Launch Your EC2 Instance
For learning Jenkins, spin up a fresh Amazon Linux 2 EC2 instance. A t2.micro is fine for the exercises in this post.
Once it is up and you are connected over SSH, let us jump straight into the installation.
Step 1: Add the Jenkins Repository
Amazon Linux 2 does not know about Jenkins out of the box. Before you can install it, you need to tell your package manager where to find Jenkins by adding the official Jenkins repository.
sudo wget -O /etc/yum.repos.d/jenkins.repo \
https://pkg.jenkins.io/redhat-stable/jenkins.repo
sudo rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io-2023.key
The first command downloads the Jenkins repository definition file. The second imports the GPG key so the package manager can verify the downloaded packages are legitimate.
Step 2: Install Java and Jenkins
Jenkins is a Java application. Without Java, Jenkins will not start. We are installing Java 21 here (Amazon Corretto is Amazon's distribution of OpenJDK):
sudo yum install java-21-amazon-corretto -y
Now install Jenkins itself:
yum install jenkins -y
Because we added the Jenkins repository in Step 1, the package manager now knows exactly where to pull Jenkins from and will install it without any confusion.
You may also want to install Git and Maven at this point, since they are commonly needed:
yum install git maven -y
Step 3: Remount /tmp with More Space
Sometimes builds fail because the /tmp partition runs out of space. Remounting it with 2GB prevents this issue:
sudo mount -o remount,size=2G /tmp
Step 4: Start Jenkins and Check the Status
By default, after installation, Jenkins is in a stopped state. Start it manually:
systemctl start jenkins.service
Verify it is running:
systemctl status jenkins.service
You should see Active: active (running) in the output. That means Jenkins is up and listening.
Step 5: Enable Jenkins to Auto-Start
If the EC2 instance stops and starts again, you want Jenkins to come back up automatically without you having to SSH in and run a start command manually.
chkconfig jenkins on
This registers Jenkins as a service that starts on boot. Highly recommended for any environment where you are not terminating the instance every time.
The Complete Installation Script
All the steps above are combined in the jenkins.sh script:
#!/bin/bash
# Install Git and Maven
yum install git maven -y
# Add the Jenkins repository
sudo wget -O /etc/yum.repos.d/jenkins.repo \
https://pkg.jenkins.io/redhat-stable/jenkins.repo
sudo rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io-2023.key
# Install Java 21 and Jenkins
sudo yum install java-21-amazon-corretto -y
yum install jenkins -y
# Expand /tmp size
sudo mount -o remount,size=2G /tmp
# Start Jenkins and check status
systemctl start jenkins.service
systemctl status jenkins.service
# Enable Jenkins to auto-start on reboot
chkconfig jenkins on
You can copy this script to your server, make it executable, and run it:
chmod +x jenkins.sh
sudo bash jenkins.sh
Step 6: Access the Jenkins Dashboard
Take the public IP address of your EC2 instance and open it in a browser with port 8080:
http://<your-ec2-public-ip>:8080
You should see a page asking for an initial administrator password.
To get this password, run:
sudo cat /var/lib/jenkins/secrets/initialAdminPassword
Copy that long string of characters, paste it into the browser, and click Continue.
Step 7: Install Suggested Plugins
Jenkins will now ask you whether to install suggested plugins or select plugins manually. Choose Install suggested plugins.
This installs a sensible set of default plugins including Git integration, pipelines, Maven support, and more. The installation takes a few minutes. Let it run.
A critical thing to understand here: Jenkins itself does not know how to talk to GitHub, Maven, Docker, or any other tool out of the box. Everything Jenkins can do with external tools depends on having the right plugin installed. Plugins are how Jenkins extends itself.
Step 8: Create Your Admin User
After plugin installation, Jenkins prompts you to create an admin user. Fill in:
Username (for example,
admin)Password
Full name
Email address
Set a Jenkins URL if prompted (the default using your IP address is fine), then click Save and Finish followed by Start using Jenkins.
Welcome to the Jenkins Dashboard
You are now looking at the Jenkins dashboard. Let us quickly orient ourselves:
New Item - this is where you create jobs (also called builds or projects)
Manage Jenkins - this is the control panel for all global configuration, plugin management, security, credentials, nodes, and system settings
Build Executor Status - shows how many builds Jenkins can run in parallel at any given time
The weather icon you see next to each job on the dashboard is Jenkins' way of showing overall job health. A sunny icon means most recent builds succeeded. A rainy or stormy icon means there have been a lot of failures. It is a quick visual health indicator.
Creating Your First Jenkins Job
Let us create a simple job to confirm everything is working.
Click New Item.
Enter a name, for example,
my-first-job.Select Freestyle project.
Click OK.
You will land on the job configuration screen. For now, scroll down to the Build Steps section. Click Add build step and select Execute shell.
In the text box that appears, type:
echo "Welcome to Jenkins!"
Click Save. You are back on the job's dashboard page.
Running the Job
Click Build Now on the left sidebar. You will see a build appear in the Build History section at the bottom left. Click on the build number, then click Console Output to see the result.
You should see:
[my-first-job] $ /bin/sh -xe /tmp/jenkins-sh.sh
+ echo 'Welcome to Jenkins!'
Welcome to Jenkins!
Finished: SUCCESS
A green circle (or "SUCCESS") means the job ran without errors. This is your first successful Jenkins build.
Understanding the Job Workspace
Every job gets its own workspace directory under the Jenkins workspace path. For a job named my-first-job, its workspace lives at:
/var/lib/jenkins/workspace/my-first-job
Any files the job creates, downloads, or generates end up here. If you create a file inside an Execute Shell step, you will find it in this directory after the build runs.
For example, if your build step contains:
echo "This is a test" > /tmp/output.txt
You can verify after the build:
cat /tmp/output.txt
Running a Shell Script from a Jenkins Job
Jenkins jobs can also run existing shell scripts on the server. If you have a script at /tmp/myscript.sh, your build step simply calls it:
sh /tmp/myscript.sh
This is powerful because you can pre-write complex automation scripts and invoke them from Jenkins without putting all the logic directly in the job configuration.
Summary
Here is what you accomplished in this post:
Added the Jenkins repository to Amazon Linux 2.
Installed Java 21 and Jenkins.
Started the service and configured auto-start.
Accessed the Jenkins dashboard via the browser.
Installed suggested plugins.
Created a first job using the Freestyle project type.
Ran the job and confirmed a successful build.
In the next post, we will explore job configuration in depth, including parameters, variables, and build triggers, the features that make Jenkins jobs truly powerful and dynamic.






