Setup Jenkins on AWS

Topic Covered:

  • Setup Jenkins
  • Git plugin install
  • S3 Artifact for jenkins
  • Junit plugin setup
  • Maven install
  • Ansible Integration (Coming Soon)

1. Setup Jenkins

Jenkins is a self-contained Java-based program, ready to run out-of-the-box, with packages for Windows, Mac OS X and other Unix-like operating systems. As an extensible automation server, Jenkins can be used as a simple CI server or turned into the continuous delivery hub for any project.

Prerequisites

  1. EC2 RHEL 7.x Instance (click here if stuck)
    • With Internet Access
    • Security Group with Port 8080 open for internet
  2. Java v1.8.x

Install Java

We will be using open java for our demo, Get latest version from http://openjdk.java.net/install/

yum install java-1.8*
#yum -y install java-1.8.0-openjdk

Confirm Java Version

Lets install java and set the java home

java -version
find /usr/lib/jvm/java-1.8* | head -n 3
#JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.191.b12-1.el7_6.x86_64
export JAVA_HOME
PATH=$PATH:$JAVA_HOME
# To set it permanently update your .bash_profile
source ~/.bash_profile

The output should be something like this,

[root@~]# java -version
openjdk version "1.8.0_151"
OpenJDK Runtime Environment (build 1.8.0_151-b12)
OpenJDK 64-Bit Server VM (build 25.151-b12, mixed mode)

Install Jenkins

You can install jenkins using the rpm or by setting up the repo. We will setup the repo so that we can update it easily in future. Get latest version of jenkins from https://pkg.jenkins.io/redhat-stable/

yum -y install wget
wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repo
rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io.key
yum -y install jenkins

Start Jenkins

# Start jenkins service
systemctl start jenkins

# Setup Jenkins to start at boot,
systemctl enable jenkins

Accessing Jenkins

By default jenkins runs at port 8080, You can access jenkins at

http://YOUR-SERVER-PUBLIC-IP:8080

Configure Jenkins

  • The default Username is admin
  • Grab the default password
    • Password Location:/var/lib/jenkins/secrets/initialAdminPassword
  • Skip Plugin Installation; We can do it later
  • Change admin password
    • Admin > Configure > Password
  • Configure java path
    • Manage Jenkins > Global Tool Configuration > JDK
  • Create another admin user id

Test Jenkins Jobs

  1. Create “new item”
  2. Enter an item name – My-First-Project
    • Chose Freestyle project
  3. Under Build section Execute shell : echo “Welcome to Jenkins Demo”
  4. Save your job
  5. Build job
  6. Check “console output”

2. Git Plugin Install

Git is one of the most popular tool for version contorl system. you can pull code from git repositories using jenkins if you use github plugin.

Install Git on Jenkins server

Install git packages on jenkins server

  yum install git -y

Setup Git on jenkins console

  • Install git plugin without restart
    • Manage Jenkins > Jenkins Plugins > available > github
  • Configure git path
    • Manage Jenkins > Global Tool Configuration > git

3. S3 Artifact for jenkins

  1. Create a S3 bucket to store artifacts
    S3 --> Create bucketBucket name: imashish.s3-artifact Region: Singapore
  2. Create new IAM role with “S3 full access” and assign it to jenkins server
    IAM --> Create role --> EC2Permission: AmazonS3FullAccess Tags: key - Name, Value - S3FullAccess Role name: S3_Full_Access
  3. Install “S3 Publisher” plugin on Jenkins
    Manage Jenkins --> Manage Plugins --> Availabe --> S3 publisher
  4. Configure S3 profile on Jenkins
    Manage Jenkins --> Configure Systems --> Amazon S3 profilesProfile name : s3-artifact-repository Use IAM Role : chose
  5. Create a job to store artifacts under S3.

4. Junit plugin setup

Setup maven on jenkins console

  • Install maven plugin without restart
    • Manage Jenkins > Jenkins Plugins > available > junit

5. Maven Install

Install Maven on Jenkins

Download maven packages https://maven.apache.org/download.cgi onto Jenkins server. In this case I am using /opt/maven as my installation directory – Link : https://maven.apache.org/download.cgi

  # Creating maven directory under /opt
  mkdir /opt/maven
  cd /opt/maven
  # downloading maven version 3.6.0
  wget http://mirrors.fibergrid.in/apache/maven/maven-3/3.6.0/binaries/apache-maven-3.6.0-bin.zip
  unzip /opt/maven/apache-maven-3.6.0-bin.zip

Setup M2_HOME and M2 paths in .bash_profile of user and add these to path variable

  vi ~/.bash_profile
  M2_HOME=/opt/maven/apache-maven-3.6.0
  M2=$M2_HOME/bin
  PAHT=<Existing_PATH>:$M2_HOME:$M2

Check point

logoff and login to check maven version Check maven version

  mvn –version

So far you have completed installation of maven software to support maven plugin on jenkins console. Let’s jump onto jenkins to complete remining steps.

Setup maven on jenkins console

  • Install maven plugin without restart
    • Manage Jenkins > Jenkins Plugins > available > Maven Invoker
  • Configure java path
    • Manage Jenkins > Global Tool Configuration > Maven

Leave a Reply

Your email address will not be published. Required fields are marked *