-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathJenkinsfile
157 lines (151 loc) · 5.71 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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#!groovy
def app
pipeline {
agent {
label 'devel11'
}
triggers {
githubPush()
}
environment {
IMAGE_NAME = "bibliotekdk-next-frontend-${env.BRANCH_NAME.toLowerCase()}:${BUILD_NUMBER}"
DOCKER_COMPOSE_NAME = "compose-${IMAGE_NAME}-${BRANCH_NAME.toLowerCase()}"
GITLAB_PRIVATE_TOKEN = credentials("metascrum-gitlab-api-token")
GITLAB_ID = "704"
CLIENT_ID = credentials("bibdk_client_id")
CLIENT_SECRET = credentials("bibdk_client_secret")
}
options {
disableConcurrentBuilds()
}
stages {
stage('clean workspace') {
steps {
cleanWs()
checkout scm
}
}
stage('Build image') {
steps {
script {
currentBuild.description = "Build ${IMAGE_NAME}"
ansiColor("xterm") {
// Work around bug https://issues.jenkins-ci.org/browse/JENKINS-44609 , https://issues.jenkins-ci.org/browse/JENKINS-44789
sh "docker build -t ${IMAGE_NAME} --pull ."
app = docker.image(IMAGE_NAME)
}
}
}
}
stage('Integration test') {
steps {
script {
// @TODO cypress:latest from docker-dbc.artifacts.dbccloud.dk
ansiColor("xterm") {
sh "docker pull docker-dbc.artifacts.dbccloud.dk/cypress:latest"
sh "docker-compose -f docker-compose-cypress.yml -p ${DOCKER_COMPOSE_NAME} build"
sh "IMAGE=${IMAGE_NAME} docker-compose -f docker-compose-cypress.yml -p ${DOCKER_COMPOSE_NAME} run --rm e2e"
}
}
}
}
stage('Push to Artifactory') {
when {
anyOf {
branch 'main';
branch 'alfa-0'
branch 'prod'
expression{env.BRANCH_NAME.startsWith('feature')}
}
}
steps {
script {
if (currentBuild.resultIsBetterOrEqualTo('SUCCESS')) {
docker.withRegistry('https://docker-frontend.artifacts.dbccloud.dk', 'docker') {
app.push()
app.push("latest")
}
}
}
}
}
stage("Update staging version number") {
agent {
docker {
label 'devel11'
image "docker-dbc.artifacts.dbccloud.dk/build-env:latest"
alwaysPull true
}
}
when {
anyOf {
branch 'main';
branch 'alfa-0'
branch 'prod'
}
}
steps {
dir("deploy") {
script {
if (env.BRANCH_NAME == 'main') {
sh '''
#!/usr/bin/env bash
set-new-version configuration.yaml ${GITLAB_PRIVATE_TOKEN} ${GITLAB_ID} ${BUILD_NUMBER} -b staging
'''
} else if (env.BRANCH_NAME == 'alfa-0') {
sh '''
#!/usr/bin/env bash
set-new-version configuration.yaml ${GITLAB_PRIVATE_TOKEN} ${GITLAB_ID} ${BUILD_NUMBER} -b alfa-0
'''
}
else if (env.BRANCH_NAME == 'prod') {
sh '''
#!/usr/bin/env bash
set-new-version configuration.yaml ${GITLAB_PRIVATE_TOKEN} ${GITLAB_ID} ${BUILD_NUMBER} -b integration
'''
}
}
}
}
}
}
post {
always {
sh '''
echo Clean up
mkdir -p logs
docker-compose -f docker-compose-cypress.yml -p ${DOCKER_COMPOSE_NAME} logs web > logs/web-log.txt
docker-compose -f docker-compose-cypress.yml -p ${DOCKER_COMPOSE_NAME} down -v
docker rmi ${IMAGE_NAME}
'''
junit skipPublishingChecks: true, testResults: 'app/e2e/reports/*.xml'
archiveArtifacts 'cypress/screenshots/*, cypress/videos/*, logs/*'
}
failure {
script {
if ("${BRANCH_NAME}" == 'main') {
slackSend(channel: 'fe-drift',
color: 'warning',
message: "${JOB_NAME} #${BUILD_NUMBER} failed and needs attention: ${BUILD_URL}",
tokenCredentialId: 'slack-global-integration-token')
}
}
}
success {
script {
if ("${BRANCH_NAME}" == 'main') {
slackSend(channel: 'fe-drift',
color: 'good',
message: "${JOB_NAME} #${BUILD_NUMBER} completed, and pushed ${IMAGE_NAME} to artifactory.",
tokenCredentialId: 'slack-global-integration-token')
}
}
}
fixed {
slackSend(channel: 'fe-drift',
color: 'good',
message: "${JOB_NAME} #${BUILD_NUMBER} back to normal: ${BUILD_URL}",
tokenCredentialId: 'slack-global-integration-token')
}
}
}