forked from opstree/spring3hibernate
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Jenkinsfile
98 lines (95 loc) · 3.56 KB
/
Jenkinsfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
pipeline {
agent any
parameters {
booleanParam(name: 'SKIP_CODE_STABILITY', defaultValue: false, description: 'Skip Code Stability Analysis')
booleanParam(name: 'SKIP_SONARQUBE_CODE_QUALITY_ANALYSIS', defaultValue: false, description: 'Skip SonarQube Analysis')
booleanParam(name: 'SKIP_CODE_COVERAGE', defaultValue: false, description: 'Skip Code Coverage Analysis')
}
stages {
stage('Code Checkout') {
steps {
git 'https://github.com/afzalhaider1/spring3hibernate.git'
}
}
stage('Build') {
steps {
sh 'mvn clean package'
}
}
stage('Parallel Stages') {
parallel {
stage('Code Stability') {
when {
expression { params.SKIP_CODE_STABILITY != true }
}
steps {
sh 'mvn pmd:pmd'
}
}
stage('SonarQube code quality analysis') {
when {
expression { params.SKIP_SONARQUBE_CODE_QUALITY_ANALYSIS != true }
}
steps {
withSonarQubeEnv('sonarQube') {
sh 'mvn sonar:sonar -Dsonar.projectKey=Spring3HibernateApp -Dsonar.projectName="Spring3HibernateApp"'
}
}
}
stage('Code Coverage Analysis') {
when {
expression { params.SKIP_CODE_COVERAGE != true }
}
steps {
sh 'mvn jacoco:report'
}
}
}
}
stage('Input') {
steps {
input('Do you want to proceed?')
}
}
stage('Publish Artifacts, If proceed') {
steps {
script {
// This stage will be executed only if the user proceeds in the "Input" stage.
nexusArtifactUploader(
nexusVersion: 'nexus3',
protocol: 'http',
nexusUrl: '172.31.31.154:8081',
groupId: 'Spring3HibernateApp',
version: '4.0.0',
repository: 'spring3hibernate',
credentialsId: 'nexus',
artifacts: [
[artifactId: 'Spring3HibernateApp',
classifier: '',
file: 'target/Spring3HibernateApp.war',
type: 'war']
]
)
}
}
}
}
post {
failure {
// Send email notification on job failure
emailext body: "The build failed. Check the console output: ${BUILD_URL}",
subject: "[FAILURE] Build failed: ${currentBuild.fullDisplayName}",
to: "[email protected]"
// Send Slack notification on job failure
slackSend(color: "danger", message: "The build failed. Check the console output: ${BUILD_URL}")
}
success {
// Send email notification on job success
emailext body: "The build succeeded. View the artifacts: ${BUILD_URL}",
subject: "[SUCCESS] Build succeeded: ${currentBuild.fullDisplayName}",
to: "[email protected]"
// Send Slack notification on job success
slackSend(color: "good", message: "The build succeeded. View the artifacts: ${BUILD_URL}")
}
}
}