-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Expand file tree
/
Copy pathJenkinsFileKubernetes
More file actions
75 lines (66 loc) · 1.88 KB
/
JenkinsFileKubernetes
File metadata and controls
75 lines (66 loc) · 1.88 KB
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
pipeline
{
agent any
tools
{
maven 'Maven_3.9.7'
}
environment
{
buildNumber = "${BUILD_NUMBER}"
}
stages
{
stage('Checkout Code to Jenkins from GitHub')
{
steps()
{
git branch: 'master', url: 'https://github.com/MithunTechnologiesDevOps/maven-web-application.git'
}
}
stage('Build Artifact using Maven')
{
steps()
{
sh 'mvn clean package'
}
}
stage('Build Docker Image')
{
steps()
{
sh 'docker build -t 149536451818.dkr.ecr.ap-south-1.amazonaws.com/maven-web-application:${buildNumber} .'
}
}
stage('Authenticate and Push Docker Image to AWS ECR')
{
steps()
{
sh 'aws ecr get-login-password --region ap-south-1 | docker login --username AWS --password-stdin 149536451818.dkr.ecr.ap-south-1.amazonaws.com'
sh 'docker push 149536451818.dkr.ecr.ap-south-1.amazonaws.com/maven-web-application:${buildNumber}'
}
}
stage('Remove Docker Image from Jenkins Locally')
{
steps()
{
sh 'docker rmi -f 149536451818.dkr.ecr.ap-south-1.amazonaws.com/maven-web-application:${buildNumber}'
}
}
stage('Update Image Tag in Kubernetes Manifest')
{
steps()
{
sh "sed -i 's/Build_Tag/${buildNumber}/g' MavenWebApplication.yaml"
}
}
stage("Deploy Application in AWS EKS Cluster")
{
steps()
{
sh 'kubectl delete deployment webpage-deployment -n production || true'
sh 'kubectl apply -f MavenWebApplication.yaml'
}
}
}
}