forked from sunnydevops2022/devops_real_time_project_1
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Jenkinsfile
77 lines (67 loc) · 2.33 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
pipeline {
agent any
environment {
PATH = "$PATH:/opt/apache-maven-3.9.1/bin"
}
stages {
stage('CLEAN WORKSPACE') {
steps {
cleanWs()
}
}
stage('CODE CHECKOUT') {
steps {
git 'https://github.com/sunnydevops2022/devops_real_time_project_1.git'
}
}
stage('MODIFIED IMAGE TAG') {
steps {
sh '''
sed "s/image-name:latest/$JOB_NAME:v1.$BUILD_ID/g" playbooks/dep_svc.yml
sed -i "s/image-name:latest/$JOB_NAME:v1.$BUILD_ID/g" playbooks/dep_svc.yml
sed -i "s/IMAGE_NAME/$JOB_NAME:v1.$BUILD_ID/g" webapp/src/main/webapp/index.jsp
'''
}
}
stage('BUILD') {
steps {
sh 'mvn clean install package'
}
}
stage('SONAR SCANNER') {
environment {
sonar_token = credentials('SONAR_TOKEN')
}
steps {
sh 'mvn sonar:sonar -Dsonar.projectName=$JOB_NAME \
-Dsonar.projectKey=$JOB_NAME \
-Dsonar.host.url=http://172.31.30.75:9000 \
-Dsonar.token=$sonar_token'
}
}
stage('COPY JAR & DOCKERFILE') {
steps {
sh 'ansible-playbook playbooks/create_directory.yml'
}
}
stage('PUSH IMAGE ON DOCKERHUB') {
environment {
dockerhub_user = credentials('DOCKERHUB_USER')
dockerhub_pass = credentials('DOCKERHUB_PASS')
}
steps {
sh 'ansible-playbook playbooks/push_dockerhub.yml \
--extra-vars "JOB_NAME=$JOB_NAME" \
--extra-vars "BUILD_ID=$BUILD_ID" \
--extra-vars "dockerhub_user=$dockerhub_user" \
--extra-vars "dockerhub_pass=$dockerhub_pass"'
}
}
stage('DEPLOYMENT ON EKS') {
steps {
sh 'ansible-playbook playbooks/create_pod_on_eks.yml \
--extra-vars "JOB_NAME=$JOB_NAME"'
}
}
}
}