Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ci jenkins #18

Open
wants to merge 21 commits into
base: ci-jenkins
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
156 changes: 73 additions & 83 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -1,121 +1,111 @@
def COLOR_MAP = [
'SUCCESS': 'good',
'FAILURE': 'danger',
]

pipeline {

agent any
/*
tools {
maven "maven3"
agent any
tools {
maven "MAVEN3"
jdk "OracleJDK8"
}
*/
environment {
NEXUS_VERSION = "nexus3"
NEXUS_PROTOCOL = "http"
NEXUS_URL = "172.31.40.209:8081"
NEXUS_REPOSITORY = "vprofile-release"
NEXUS_REPOGRP_ID = "vprofile-grp-repo"
NEXUS_CREDENTIAL_ID = "nexuslogin"
ARTVERSION = "${env.BUILD_ID}"
SNAP_REPO = 'vprofile-snapshot'
NEXUS_USER = 'admin'
NEXUS_PASS = 'admin123'
RELEASE_REPO = 'vprofile-release'
CENTRAL_REPO = 'vpro-maven-central'
NEXUSIP = '172.31.88.91'
NEXUSPORT = '8081'
NEXUS_GRP_REPO = 'vpro-maven-group'
NEXUS_LOGIN = 'nexuslogin'
SONARSERVER = 'sonarserver'
SONARSCANNER = 'sonarscanner'
}

stages{

stage('BUILD'){

stages {
stage('Build'){
steps {
sh 'mvn clean install -DskipTests'
sh 'mvn -DskipTests install'
}
post {
success {
echo 'Now Archiving...'
archiveArtifacts artifacts: '**/target/*.war'
echo "Now Archiving."
archiveArtifacts artifacts: '**/*.war'
}
}
}

stage('UNIT TEST'){
stage('Test'){
steps {
sh 'mvn test'
}
}

stage('INTEGRATION TEST'){
steps {
sh 'mvn verify -DskipUnitTests'
}
}
stage ('CODE ANALYSIS WITH CHECKSTYLE'){

stage('Checkstyle Analysis'){
steps {
sh 'mvn checkstyle:checkstyle'
}
post {
success {
echo 'Generated Analysis Result'
}
}
}

stage('CODE ANALYSIS with SONARQUBE') {

environment {
scannerHome = tool 'sonarscanner4'
}

steps {
withSonarQubeEnv('sonar-pro') {
sh '''${scannerHome}/bin/sonar-scanner -Dsonar.projectKey=vprofile \
-Dsonar.projectName=vprofile-repo \
stage('Sonar Analysis') {
environment {
scannerHome = tool "${SONARSCANNER}"
}
steps {
withSonarQubeEnv("${SONARSERVER}") {
sh '''${scannerHome}/bin/sonar-scanner -Dsonar.projectKey=vprofile \
-Dsonar.projectName=vprofile \
-Dsonar.projectVersion=1.0 \
-Dsonar.sources=src/ \
-Dsonar.java.binaries=target/test-classes/com/visualpathit/account/controllerTest/ \
-Dsonar.junit.reportsPath=target/surefire-reports/ \
-Dsonar.jacoco.reportsPath=target/jacoco.exec \
-Dsonar.java.checkstyle.reportPaths=target/checkstyle-result.xml'''
}
}

timeout(time: 10, unit: 'MINUTES') {
waitForQualityGate abortPipeline: true
}
}
}

stage("Publish to Nexus Repository Manager") {
stage("Quality Gate") {
steps {
script {
pom = readMavenPom file: "pom.xml";
filesByGlob = findFiles(glob: "target/*.${pom.packaging}");
echo "${filesByGlob[0].name} ${filesByGlob[0].path} ${filesByGlob[0].directory} ${filesByGlob[0].length} ${filesByGlob[0].lastModified}"
artifactPath = filesByGlob[0].path;
artifactExists = fileExists artifactPath;
if(artifactExists) {
echo "*** File: ${artifactPath}, group: ${pom.groupId}, packaging: ${pom.packaging}, version ${pom.version} ARTVERSION";
nexusArtifactUploader(
nexusVersion: NEXUS_VERSION,
protocol: NEXUS_PROTOCOL,
nexusUrl: NEXUS_URL,
groupId: NEXUS_REPOGRP_ID,
version: ARTVERSION,
repository: NEXUS_REPOSITORY,
credentialsId: NEXUS_CREDENTIAL_ID,
artifacts: [
[artifactId: pom.artifactId,
classifier: '',
file: artifactPath,
type: pom.packaging],
[artifactId: pom.artifactId,
classifier: '',
file: "pom.xml",
type: "pom"]
]
);
}
else {
error "*** File: ${artifactPath}, could not be found";
}
timeout(time: 1, unit: 'HOURS') {
// Parameter indicates whether to set pipeline to UNSTABLE if Quality Gate fails
// true = set pipeline to UNSTABLE, false = don't
waitForQualityGate abortPipeline: true
}
}
}



stage("UploadArtifact"){
steps{
nexusArtifactUploader(
nexusVersion: 'nexus3',
protocol: 'http',
nexusUrl: "${NEXUSIP}:${NEXUSPORT}",
groupId: 'QA',
version: "${env.BUILD_ID}-${env.BUILD_TIMESTAMP}",
repository: "${RELEASE_REPO}",
credentialsId: "${NEXUS_LOGIN}",
artifacts: [
[artifactId: 'vproapp',
classifier: '',
file: 'target/vprofile-v2.war',
type: 'war']
]
)
}
}
}


post {
always {
echo 'Slack Notifications.'
slackSend channel: '#vprofilecicd',
color: COLOR_MAP[currentBuild.currentResult],
message: "*${currentBuild.currentResult}:* Job ${env.JOB_NAME} build ${env.BUILD_NUMBER} \n More info at: ${env.BUILD_URL}"
}
}

}
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,8 @@
</build>
<repositories>
<repository>
<id>${NEXUS-GRP-REPO}</id>
<url>http://${NEXUSIP}:${NEXUSPORT}/repository/${NEXUS-GRP-REPO}/</url>
<id>${NEXUS_GRP_REPO}</id>
<url>http://${NEXUSIP}:8081/repository/${NEXUS_GRP_REPO}/</url>
</repository>
</repositories>
</project>
30 changes: 15 additions & 15 deletions settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,32 @@

<servers>
<server>
<id>${SNAP-REPO}</id>
<username>${NEXUS-USER}</username>
<password>${NEXUS-PASS}</password>
<id>${SNAP_REPO}</id>
<username>${NEXUS_USER}</username>
<password>${NEXUS_PASS}</password>
</server>
<server>
<id>${RELEASE-REPO}</id>
<username>${NEXUS-USER}</username>
<password>${NEXUS-PASS}</password>
<id>${RELEASE_REPO}</id>
<username>${NEXUS_USER}</username>
<password>${NEXUS_PASS}</password>
</server>
<server>
<id>${CENTRAL-REPO}</id>
<username>${NEXUS-USER}</username>
<password>${NEXUS-PASS}</password>
<id>${CENTRAL_REPO}</id>
<username>${NEXUS_USER}</username>
<password>${NEXUS_PASS}</password>
</server>
<server>
<id>${NEXUS-GRP-REPO}</id>
<username>${NEXUS-USER}</username>
<password>${NEXUS-PASS}</password>
<id>${NEXUS_GRP_REPO}</id>
<username>${NEXUS_USER}</username>
<password>${NEXUS_PASS}</password>
</server>
</servers>

<mirrors>
<mirror>
<id>${CENTRAL-REPO}</id>
<name>${CENTRAL-REPO}</name>
<url>http://${NEXUSIP}:${NEXUSPORT}/repository/${NEXUS-GRP-REPO}/</url>
<id>${CENTRAL_REPO}</id>
<name>${CENTRAL_REPO}</name>
<url>http://${NEXUSIP}:${NEXUSPORT}/repository/${NEXUS_RP_REPO}/</url>
<mirrorOf>*</mirrorOf>
</mirror>
</mirrors>
Expand Down