-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
137 lines (127 loc) · 4.36 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#!groovy
def app
def imageName="fbi-api-gateway"
def imageLabel=BUILD_NUMBER
pipeline {
agent {
label 'devel10'
}
triggers{
// @TODO parameters on githubPush .. eg. branch
githubPush()
}
environment {
GITLAB_ID = "1232"
DOCKER_TAG = "${imageLabel}"
IMAGE = "${imageName}${env.BRANCH_NAME != 'master' ? "-${env.BRANCH_NAME.toLowerCase()}" : ''}:${BUILD_NUMBER}"
DOCKER_COMPOSE_NAME = "compose-${IMAGE}"
// we need to use metascrums gitlab token .. for the metascrum bot in deploy stage
GITLAB_PRIVATE_TOKEN = credentials("metascrum-gitlab-api-token")
REPOSITORY = "https://docker-frontend.artifacts.dbccloud.dk"
}
stages {
stage('Build image') {
steps { script {
// Work around bug https://issues.jenkins-ci.org/browse/JENKINS-44609 , https://issues.jenkins-ci.org/browse/JENKINS-44789
sh "docker build -t ${IMAGE} --pull --no-cache ."
app = docker.image("${IMAGE}")
} }
}
stage('Integration test') {
steps {
script {
ansiColor("xterm") {
sh "echo Integrating..."
// sh "docker-compose -f docker-compose-cypress.yml -p ${DOCKER_COMPOSE_NAME} build"
// sh "IMAGE=${IMAGE} docker-compose -f docker-compose-cypress.yml -p ${DOCKER_COMPOSE_NAME} run e2e"
}
}
}
}
stage('Push to Artifactory') {
when { anyOf { branch 'master'; branch 'future' } }
steps {
script {
if (currentBuild.resultIsBetterOrEqualTo('SUCCESS')) {
docker.withRegistry("${REPOSITORY}", 'docker') {
app.push()
app.push("latest")
}
}
} }
}
stage("Update 'staging' version number") {
agent {
docker {
label 'devel10'
image "docker-dbc.artifacts.dbccloud.dk/build-env:latest"
alwaysPull true
}
}
when {
branch 'master'
}
steps {
dir("deploy") {
sh """#!/usr/bin/env bash
set-new-version configuration.yaml ${env.GITLAB_PRIVATE_TOKEN} ${env.GITLAB_ID} ${env.DOCKER_TAG} -b staging
"""
}
}
}
stage("Update 'future' version number") {
agent {
docker {
label 'devel10'
image "docker-dbc.artifacts.dbccloud.dk/build-env:latest"
alwaysPull true
}
}
when {
branch 'future'
}
steps {
dir("deploy") {
sh """#!/usr/bin/env bash
set-new-version configuration.yaml ${env.GITLAB_PRIVATE_TOKEN} ${env.GITLAB_ID} ${env.DOCKER_TAG} -b future
"""
}
}
}
}
post {
always {
sh """
echo Clean up
#docker-compose -f docker-compose-cypress.yml -p ${DOCKER_COMPOSE_NAME} down -v
docker rmi $IMAGE
"""
}
failure {
script {
if ("${env.BRANCH_NAME}" == 'master') {
slackSend(channel: 'fe-drift',
color: 'warning',
message: "${env.JOB_NAME} #${env.BUILD_NUMBER} failed and needs attention: ${env.BUILD_URL}",
tokenCredentialId: 'slack-global-integration-token')
}
}
}
success {
script {
if ("${env.BRANCH_NAME}" == 'master') {
slackSend(channel: 'fe-drift',
color: 'good',
message: "${env.JOB_NAME} #${env.BUILD_NUMBER} completed, and pushed ${IMAGE} to artifactory.",
tokenCredentialId: 'slack-global-integration-token')
}
}
}
fixed {
slackSend(channel: 'fe-drift',
color: 'good',
message: "${env.JOB_NAME} #${env.BUILD_NUMBER} back to normal: ${env.BUILD_URL}",
tokenCredentialId: 'slack-global-integration-token')
}
}
}