-
Notifications
You must be signed in to change notification settings - Fork 3
/
Jenkinsfile
86 lines (86 loc) · 3.19 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
pipeline {
options {
timestamps()
skipDefaultCheckout()
disableConcurrentBuilds()
}
agent {
node { label 'translator && build && aws && ui' }
}
parameters {
string(name: 'BUILD_VERSION', defaultValue: '', description: 'The build version to deploy (optional)')
string(name: 'AWS_REGION', defaultValue: 'us-east-1', description: 'AWS Region to deploy')
}
triggers {
pollSCM('H/5 * * * *')
}
environment {
IMAGE_NAME = "853771734544.dkr.ecr.us-east-1.amazonaws.com/translator-ui"
KUBERNETES_BLUE_CLUSTER_NAME = "translator-eks-ci-blue-cluster"
DEPLOY_ENV="ci"
NAMESPACE='ui'
}
stages {
stage('Build Version'){
when { expression { return !params.BUILD_VERSION } }
steps{
script {
BUILD_VERSION_GENERATED = VersionNumber(
versionNumberString: 'v${BUILD_YEAR, XX}.${BUILD_MONTH, XX}${BUILD_DAY, XX}.${BUILDS_TODAY}',
projectStartDate: '1970-01-01',
skipFailedBuilds: true)
currentBuild.displayName = BUILD_VERSION_GENERATED
env.BUILD_VERSION = BUILD_VERSION_GENERATED
env.BUILD = 'true'
}
}
}
stage('Checkout source code') {
steps {
cleanWs()
checkout scm
}
}
stage('Build Docker') {
when { expression { return env.BUILD == 'true' }}
steps {
script {
sh '''#!/bin/bash
source build-docker-container.sh -b main -f main
aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin 853771734544.dkr.ecr.us-east-1.amazonaws.com
docker image tag $image_name:$version_tag $IMAGE_NAME
'''
docker.image(env.IMAGE_NAME).push("${BUILD_VERSION}")
}
}
}
stage('Deploy to AWS EKS Blue') {
agent {
label 'translator && ci && deploy'
}
steps {
script {
configFileProvider([
configFile(fileId: 'values-ci.yaml', targetLocation: 'values-ncats.yaml'),
configFile(fileId: 'secrets.json', targetLocation: 'secrets.json'),
configFile(fileId: 'prepare.sh', targetLocation: 'prepare.sh')
]){
sh '''
kubectl delete deployment translator-ui -n ${NAMESPACE}
aws --region ${AWS_REGION} eks update-kubeconfig --name ${KUBERNETES_BLUE_CLUSTER_NAME}
/bin/bash prepare.sh
cd translator-ops/ops/translator-ui/
/bin/bash deploy.sh
'''
}
}
}
post {
always {
echo " Clean up the workspace in deploy node!"
cleanWs()
}
}
}
}
}