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
- EC2 RHEL 7.x Instance (click here if stuck)
- With Internet Access
- Security Group with Port
8080
open for internet
- 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
- Password Location:
Skip
Plugin Installation; We can do it later- Change admin password
Admin
>Configure
>Password
- Configure
java
pathManage Jenkins
>Global Tool Configuration
>JDK
- Create another admin user id
Test Jenkins Jobs
- Create “new item”
- Enter an item name –
My-First-Project
- Chose
Freestyle
project
- Chose
- Under Build section Execute shell : echo “Welcome to Jenkins Demo”
- Save your job
- Build job
- 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
- Create a S3 bucket to store artifacts
S3 --> Create bucket
Bucket name: imashish.s3-artifact Region: Singapore - 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
- Install “S3 Publisher” plugin on Jenkins
Manage Jenkins --> Manage Plugins --> Availabe --> S3 publisher
- Configure S3 profile on Jenkins
Manage Jenkins --> Configure Systems --> Amazon S3 profiles
Profile name : s3-artifact-repository Use IAM Role : chose - 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