This repository has been archived by the owner on Sep 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Jenkinsfile
77 lines (74 loc) · 2.22 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
stages{
stage('Prepare Build'){
steps{
script{
hash = sh(returnStdout: true, script: 'git rev-parse HEAD').trim()
VERSION = hash.take(7)
currentBuild.displayName = "#${BUILD_ID}-${VERSION}"
sh("eval \$(aws ecr --region us-east-1 get-login --no-include-email)")
}
}
}
stage('Build ImageGenerator'){
steps{
script{
def imageGenerator = docker.build("fecfile-imagegenerator:${VERSION}", ".")
docker.withRegistry('https://813218302951.dkr.ecr.us-east-1.amazonaws.com/fecfile-imagegenerator'){
imageGenerator.push()
}
}
}
}
stage('Deploy Dev'){
when { branch 'develop' }
steps {
deployImage16("${VERSION}", "dev")
code_quality("${BUILD_ID}", "${VERSION}")
}
}
stage('Deploy QA'){
when { branch 'release' }
steps {
deployImage16("${VERSION}", "qa")
}
}
stage('Deploy UAT'){
when { branch 'main' }
steps {
deployImage16("${VERSION}", "uat")
}
}
}
post{
success {
slackSend color: 'good', message: env.BRANCH_NAME + ": Deployed ${VERSION} to k8s dev-efile-api.efdev.fec.gov/printpdf/"
}
failure {
slackSend color: 'danger', message: env.BRANCH_NAME + ": deployment of fecfile-imagegenerator versoin: ${VERSION} failed!"
}
}
}
def deployImage(String version, String toEnv) {
sh """
kubectl \
--context=arn:aws:eks:us-east-1:813218302951:cluster/fecfile4 \
--namespace=${toEnv} \
set image deployment/fecfile-imagegenerator \
fecfile-imagegenerator=813218302951.dkr.ecr.us-east-1.amazonaws.com/fecfile-imagegenerator:${version}
"""
}
def deployImage16(String version, String toEnv) {
sh """
kubectl16 \
--context=arn:aws:eks:us-east-1:813218302951:cluster/fecnxg-dev1 \
--namespace=${toEnv} \
set image deployment/fecfile-imagegenerator \
fecfile-imagegenerator=813218302951.dkr.ecr.us-east-1.amazonaws.com/fecfile-imagegenerator:${version}
"""
}
def code_quality(String id, String hash) {
sh(""" sh successful_test.sh "${id}" ${hash} """)
junit '**/reports/*.xml'
}