Skip to content
Open

Cicd #167

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
184 changes: 93 additions & 91 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -1,121 +1,123 @@
def COLOR_MAP = [
'SUCCESS': 'good',
'FAILURE': 'danger',
]
pipeline {

agent any
/*
tools {
maven "maven3"
}
*/
environment {
NEXUS_VERSION = "nexus3"
NEXUS_PROTOCOL = "http"
NEXUS_URL = "172.31.40.209:8081"
NEXUS_REPOSITORY = "vprofile-release"
NEXUS_REPO_ID = "vprofile-release"
NEXUS_CREDENTIAL_ID = "nexuslogin"
ARTVERSION = "${env.BUILD_ID}"
}

stages{

stage('BUILD'){
maven "MAVEN3.9"
jdk "JDK17"
}

stages {

stage('test slack'){
steps{
sh 'NotARealCommand'

}
}
stage('Fetch code') {
steps {
sh 'mvn clean install -DskipTests'
}
post {
success {
echo 'Now Archiving...'
archiveArtifacts artifacts: '**/target/*.war'
}
git branch: 'cicd', url: 'https://github.com/jkabirqa/aheeva-project.git'
}
}

stage('UNIT TEST'){
steps {
}


stage('Build'){
steps{
sh 'mvn install -DskipTests'
}

post {
success {
echo 'Now Archiving it...'
archiveArtifacts artifacts: '**/target/*.war'
}
}
}

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

stage('INTEGRATION TEST'){
steps {
sh 'mvn verify -DskipUnitTests'
}
}

stage ('CODE ANALYSIS WITH CHECKSTYLE'){
steps {
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 Code Analysis") {
environment {
scannerHome = tool 'sonar6.2'
}
steps {
withSonarQubeEnv('sonarserver') {
sh '''${scannerHome}/bin/sonar-scanner -Dsonar.projectKey=vprofile \
-Dsonar.projectName=aheeva \
-Dsonar.projectVersion=1.0 \
-Dsonar.sources=src/ \
-Dsonar.java.binaries=target/test-classes/com/visualpathit/account/controllerTest/ \
-Dsonar.java.binaries=target/test-classes/com/aheeva/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("Quality Gate") {
steps {
timeout(time: 1, unit: 'HOURS') {
waitForQualityGate abortPipeline: true
}
}
}
}

stage("Publish to Nexus Repository Manager") {
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: pom.groupId,
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";
}
}
/* ==== UI TESTING ==== */
stage('UI-Test -Selenium'){
steps{
sh 'mvn -pl qa-tests/ui-tests test'
}
post{
always{
junit '**/ui-tests/target/surefire-reports/*.xml'
}
}
}

stage("UploadArtifact"){
steps{
nexusArtifactUploader(
nexusVersion: 'nexus3',
protocol: 'http',
nexusUrl: '172.31.25.14:8081',
groupId: 'QA',
version: "${env.BUILD_ID}-${env.BUILD_TIMESTAMP}",
repository: 'aheeva-project',
credentialsId: 'nexuslogin',
artifacts: [
[artifactId: 'aheevaapp',
classifier: '',
file: 'target/aheeva-v2.war',
type: 'war']
]
)
}
}


}
}

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

}
}
111 changes: 111 additions & 0 deletions Jenkinsfile.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
def COLOR_MAP = [
'SUCCESS': 'good',
'FAILURE': 'danger',
]
pipeline {
agent any
tools {
maven "MAVEN3.9"
jdk "JDK17"
}

stages {

stage('test slack'){
steps{
sh 'NotARealCommand'

}
}
stage('Fetch code') {
steps {
git branch: 'atom', url: 'https://github.com/hkhcoder/vprofile-project.git'
}

}


stage('Build'){
steps{
sh 'mvn install -DskipTests'
}

post {
success {
echo 'Now Archiving it...'
archiveArtifacts artifacts: '**/target/*.war'
}
}
}

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

stage('Checkstyle Analysis') {
steps{
sh 'mvn checkstyle:checkstyle'
}
}

stage("Sonar Code Analysis") {
environment {
scannerHome = tool 'sonar6.2'
}
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'''
}
}
}

stage("Quality Gate") {
steps {
timeout(time: 1, unit: 'HOURS') {
waitForQualityGate abortPipeline: true
}
}
}

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


}

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

}
Loading