DEV Community

vaibhav aggarwal
vaibhav aggarwal

Posted on

Setting up Jenkins on AWS

This tutorial walks you through the process of deploying a Jenkins application.

  • You will launch an EC2 instance (centOS), install and configure Jenkins.
  • Jenkins to automatically spin up Jenkins build slave instances if build abilities need to be augmented on the instance.

Launch and Setup an EC2 instance

First, launch an ec2 instance to install and run jenkins. Steps involved are:

  1. launch an ec2 instance

Screenshot

  1. Add secutiry group

image

  1. ssh into the instance: select initiated instance, proceed to connect and follow the instructions. Make sure you are in the same folder as your downloaded .pem key.
    chmod 400 jenkins-ec2.pem //if you named the instance same
    ssh -i "jenkins-ec2.pem" ec2-user@ec2-13-127-31-75.ap-south-1.compute.amazonaws.com //please check your details

Install and run Jenkins

Here, we will connect to the instance and run the jenkins after all necessary installation.
Steps covered:

  1. connect to your instance
  2. download and install jenkins
  3. configure jenkins

After connecting to your ec2 instance via ssh, jenkins need to be download and installed.

    sudo yum update -y //update system
    sudo yum install java-1.8.0-openjdk-devel //install jdk
    curl --silent --location http://pkg.jenkins-ci.org/redhat-stable/jenkins.repo | sudo tee /etc/yum.repos.d/jenkins.repo //get GPG key
    sudo rpm --import https://jenkins-ci.org/redhat/jenkins-ci.org.key //add repo to system 
    sudo yum install jenkins //install jenkins

    // start the service
    sudo systemctl start jenkins
    //check service status
    systemctl status jenkins.service

On checking jenkins service status, an output like this is expected.

jenkins running screenshot

Voila! Jenkins is installed and running at port 8080 on your instance.
But remember, there is no access to port 8080 to outside world. Security groups are used for the purpose of protecting our running instances from outside attack. Let's go to attached security group and edit inbound rules.

Screenshot 2020-04-27 at 5 30 36 PM

  • Open a browser window and access your jenkins instance running on your_ec2_public_ip:8080

  • access your initial administator password for jenkins using (ec2 terminal).

    sudo cat /var/lib/jenkins/secrets/initialAdminPassword
  • Select install selected plugins and wait for it. Its almost done. Create a user if needed other than admin. Jenkins ready screen will appear. We are all set to automate our CI process.

create-jenkins-user

Go to manage jenkins and toggle to install plugins.

Screenshot 2020-04-27 at 5 23 19 PM

Jenkins is up and running on AWS.
"Please note for security reasons, never expose your public IP. Always have it running behind a reverse proxy."

In next article, we will create a Jenkins project and integrate it with github. That will be the first step to create a Continuous Integration pipeline.

P.S. "Above written are my views. I am always learning and exploring new things. Please comment and criticize wherever possible. Stay Happy."

Helpful links

  1. https://jenkins.io/
  2. github on centOS

Top comments (2)

Collapse
 
qainsights profile image
NaveenKumar Namachivayam ⚡

Good read. You can also add running Jenkins using docker container on AWS :)

Collapse
 
alakazam03 profile image
vaibhav aggarwal

Yes, Naveen absolutely. That will be too easy and better. I was just trying to set up things one at time for CI/CD pipeline.