-
Notifications
You must be signed in to change notification settings - Fork 354
/
Jenkinsfile
104 lines (103 loc) · 2.58 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
99
100
101
102
103
104
def COLOR_MAP = [
'SUCCESS': 'good',
'FAILURE': 'danger',
]
pipeline {
agent any
environment {
WORKSPACE = "${env.WORKSPACE}"
}
tools {
maven 'localMaven'
jdk 'localJdk'
}
stages {
stage('Build') {
steps {
sh 'mvn clean package'
}
post {
success {
echo ' now Archiving '
archiveArtifacts artifacts: '**/*.war'
}
}
}
stage('Unit Test'){
steps {
sh 'mvn test'
}
}
stage('Integration Test'){
steps {
sh 'mvn verify -DskipUnitTests'
}
}
stage ('Checkstyle Code Analysis'){
steps {
sh 'mvn checkstyle:checkstyle'
}
post {
success {
echo 'Generated Analysis Result'
}
}
}
stage('SonarQube Scan') {
steps {
sh """mvn sonar:sonar \
-Dsonar.projectKey=JavaWebApp \
-Dsonar.host.url=http://172.31.4.143:9000 \
-Dsonar.login=e9733df3fcd6ed54cef307d8ac4cc00eeb2d3611"""
}
}
stage('Upload to Artifactory') {
steps {
sh "mvn clean deploy -DskipTests"
}
}
stage('Deploy to DEV') {
environment {
HOSTS = "dev"
}
steps {
sh "ansible-playbook ${WORKSPACE}/deploy.yaml --extra-vars \"hosts=$HOSTS workspace_path=$WORKSPACE\""
}
}
// stage('Approval for stage') {
// steps {
// input('Do you want to proceed?')
// }
// }
stage('Deploy to Stage') {
environment {
HOSTS = "stage" // Make sure to update to "stage"
}
steps {
sh "ansible-playbook ${WORKSPACE}/deploy.yaml --extra-vars \"hosts=$HOSTS workspace_path=$WORKSPACE\""
}
}
stage('Approval') {
steps {
input('Do you want to proceed?')
}
}
stage('Deploy to PROD') {
environment {
HOSTS = "prod"
}
steps {
sh "ansible-playbook ${WORKSPACE}/deploy.yaml --extra-vars \"hosts=$HOSTS workspace_path=$WORKSPACE\""
}
}
}
post {
always {
echo 'Slack Notifications.'
slackSend channel: '#mbandi-jenkins-cicd-pipeline-alerts', //update and provide your channel name
color: COLOR_MAP[currentBuild.currentResult],
message: "*${currentBuild.currentResult}:* Job ${env.JOB_NAME} build ${env.BUILD_NUMBER} \n More info at: ${env.BUILD_URL}"
}
}
}
//slackSend channel: '#mbandi-cloudformation-cicd', message: "Please find the pipeline status of the following ${env.JOB_NAME ${env.BUILD_NUMBER} ${env.BUILD_URL}"