-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathjenkinsfile
96 lines (76 loc) · 2.84 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
pipeline {
agent any
stages {
stage('SCM_Checkout') {
steps {
checkout scmGit(branches: [[name: '*/master']], extensions: [], userRemoteConfigs: [[credentialsId: 'git_repo_pass', url: 'https://github.com/Venkateshd279/my-project.git']])
}
}
stage('SonarQube Analysis') {
steps {
script {
withSonarQubeEnv(credentialsId: 'SonarQube_token') {
sh 'mvn clean verify sonar:sonar'
}
}
}
}
stage("Quality Gate") {
steps {
sleep(60)
timeout(time: 1, unit: 'HOURS') {
waitForQualityGate abortPipeline: true, credentialsId: 'SonarQube_token'
}
}
post {
failure {
echo 'sending email notification from jenkins'
step([$class: 'Mailer',
notifyEveryUnstableBuild: true,
recipients: emailextrecipients([[$class: 'CulpritsRecipientProvider'],
[$class: 'RequesterRecipientProvider']])])
}
}
}
stage('Maven Compile') {
steps {
sh 'whoami'
sh script: 'mvn clean install'
sh 'mv target/myweb*.war target/newapp.war'
}
}
stage('Build Docker Image') {
steps {
script {
sh 'cd /var/lib/jenkins/workspace/Onlineshopping'
def dockerImage = docker.build("venkateshdhanap/myweb:0.0.2", "--file Dockerfile .")
}
}
}
stage('Push Image to ECR') {
steps {
script {
docker.withRegistry(
'https://477099163803.dkr.ecr.ap-south-1.amazonaws.com',
'ecr:ap-south-1:my.aws.credentials') {
def myImage = docker.build('jenkins_project')
myImage.push('latest')
}
}
}
}
stage('Approval - Deploy EKS'){
steps {
input 'Approve for EKS Deploy'
}
}
stage('EKS Deploy') {
steps {
echo 'Deploying on EKS'
withKubeCredentials(kubectlCredentials: [[caCertificate: '', clusterName: '', contextName: '', credentialsId: 'k8s', namespace: '', serverUrl: '']]) {
sh 'kubectl apply -f /var/lib/jenkins/mainservice.yaml'
}
}
}
}
}