-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathJenkinsfile
82 lines (75 loc) · 2.59 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
pipeline {
agent any
stages {
stage('SCM checkout') {
steps {
git 'https://github.com/Skrishnan586/Rajkot.git'
}
}
stage('SonarQube Analysis') {
steps {
script {
def scannerHome = tool 'sonarscanner4'
withSonarQubeEnv('sonar-pro') {
sh "${scannerHome}/bin/sonar-scanner -Dsonar.projectKey=Rajkot"
}
}
}
}
stage('Quality Gate') {
steps {
sleep(time: 35, unit: 'SECONDS')
timeout(time: 1, unit: 'HOURS') {
waitForQualityGate abortPipeline: true, credentialsId: 'sonar'
}
}
post {
failure {
echo 'Sending email notification from Jenkins'
step([$class: 'Mailer',
notifyEveryUnstableBuild: true,
recipients: emailextrecipients([[$class: 'CulpritsRecipientProvider'],
[$class: 'RequesterRecipientProvider']])])
}
}
}
stage('Build Docker Image') {
steps {
script {
sh 'cd /var/lib/jenkins/workspace/Rajkot'
def dockerImage = docker.build("harikrishnan/rajkot-hospital", "--file Dockerfile .")
}
}
}
stage('Push Image to ECR') {
steps {
script {
docker.withRegistry(
'https://572679073520.dkr.ecr.ap-south-1.amazonaws.com/automated-deployment',
'ecr:ap-south-1:my.aws.credentials') {
def myImage = docker.build('automated-deployment')
myImage.push('latest')
}
}
}
}
stage('Approval - Deploy on k8s') {
steps {
input 'Approve for EKS Deploy'
}
}
stage('Deploy on k8s') {
steps {
parallel (
'deploy on k8s': {
script {
withKubeCredentials(kubectlCredentials: [[credentialsId: 'k8s', namespace: 'default']]) {
sh 'kubectl apply -f /var/lib/jenkins/mainservice.yaml'
}
}
}
)
}
}
}
}