Run Maven project from Jenkins and publish the war file on Amazon S3
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.
8080
open for internetWe 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
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)
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 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
admin
/var/lib/jenkins/secrets/initialAdminPassword
Skip
Plugin Installation; We can do it laterAdmin
> Configure
> Password
java
pathManage Jenkins
> Global Tool Configuration
> JDK
My-First-Project
Freestyle
projectCreate a Jenkins Pipeline
def workspace;
node
{
stage('Checkout')
{
checkout([$class: 'GitSCM', branches: [[name: '*/master']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: '0e58c990-80af-43ea-9f55-85c176bba12b', url: 'https://github.com/rkidambi11/maven.git']]])
workspace =pwd()
}
stage('Static Code Analysis')
{
echo "Static Code Analysis"
}
stage('Build')
{
echo "Build the code"
}
stage('Unit Testing')
{
echo "Unit Testing"
}
stage ('Delivery')
{
echo "Devliver the Code"
}
}
node {
stage('scm checkout for api test'){
git credentialsId: '2bf8a43e-4698-4cd4-a5b5-4109e16794b9', url: 'https://github.com/rkidambi11/maven.git'
}
stage ('maven package'){
echo " API package will going to start"
def mvnHome=tool name: 'M3', type: 'maven'
sh "'${mvnHome}/bin/mvn' -Dmaven.test.failure.ignore clean package"
}
stage('Test') {
//Perform test
echo 'Execute the script'
def mvnHome=tool name: 'M3', type: 'maven'
sh "'${mvnHome}/bin/mvn' -Dmaven.test.failure.ignore test"
}
stage('Results') {
junit '**/target/surefire-reports/TEST-*.xml'
archive 'target/*.jar'
}
}