forked from dittowords/ditto-ce-connector
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Jenkinsfile.promote
80 lines (72 loc) · 2.63 KB
/
Jenkinsfile.promote
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
def REGISTRY_CREDENTIAL_ID = "DOCKER_REGISTRY"
def CI_ENV_IMAGE = "053497547689.dkr.ecr.eu-central-1.amazonaws.com/tools/ci-env:v0.16.0"
def NODE_TAG = "lok-cteng-conn-${ENV}"
def NORELEASE = ""
def tag
def nodes = [:]
node('build') {
properties([
parameters([
choice(choices: ['stage', 'live'], name: 'ENV'),
gitParameter(name: 'TAG', type: 'PT_TAG', defaultValue: 'latest', sortMode: 'DESCENDING_SMART', selectedValue: 'TOP', listSize: '5'),
booleanParam(description: 'If checked, deploy to LIVE env will be skipped', name: 'NORELEASE'),
]),
pipelineTriggers([githubPush()])
])
stage("Checkout") {
checkout(scm)
}
stage("Job-info") {
currentBuild.displayName = "#${BUILD_NUMBER}-${ENV}"
currentBuild.description = "TAG: ${TAG}"
}
}
nodesByLabel(NODE_TAG).each {
nodes[it] = { ->
node(it) {
withCredentials([
usernamePassword(
credentialsId: REGISTRY_CREDENTIAL_ID,
usernameVariable: "REGISTRY_USER",
passwordVariable: "REGISTRY_PASSWORD"
)
]) {
docker.image(CI_ENV_IMAGE).inside("--net=host -u root:root -v /var/run/docker.sock:/var/run/docker.sock") {
stage("Checkout") {
scmVars = checkout(scm)
currentBuild.displayName = "#${BUILD_NUMBER}-${ENV}"
currentBuild.description = "TAG: ${TAG}"
}
stage("Deploy @ ${it}") {
sh 'TAG=${TAG} ENV=${ENV} docker/scripts/deploy.sh'
}
stage("Healthcheck @ ${it}") {
sh 'TAG=${TAG} ENV=${ENV} docker/scripts/health.sh "http://localhost:3009/health" "200"'
}
}
}
}
}
}
parallel nodes
node('build') {
stage('Post-Deploy') {
if (ENV == 'live') {
withCredentials([string(credentialsId: 'GITHUB_TOKEN', variable: 'GITHUB_TOKEN')]) {
sh 'TAG=${TAG} docker/scripts/release.sh git_release $(git rev-parse HEAD)'
}
}
else {
withCredentials([string(credentialsId: 'GITHUB_TOKEN', variable: 'GITHUB_TOKEN')]) {
sh 'TAG=${TAG} docker/scripts/release.sh check_norelease $(git rev-parse HEAD)'
}
withCredentials([string(credentialsId: 'GITHUB_TOKEN', variable: 'GITHUB_TOKEN')]) {
echo "Promoting tag ${TAG} to the LIVE env..."
build job: 'promote', wait: false, parameters: [
[$class: 'StringParameterValue', name: 'TAG', value: "${TAG}"],
[$class: 'StringParameterValue', name: 'ENV', value: "live"],
]
}
}
}
}