-
Notifications
You must be signed in to change notification settings - Fork 2
/
Jenkinsfile
107 lines (105 loc) · 3.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
#!groovy
def app
def imageName = 'fbs-cms-adapter'
def imageLabel = BUILD_NUMBER
pipeline {
agent {
label 'devel10-head'
}
environment {
GITLAB_ID = "1048"
DOCKER_TAG = "${imageLabel}"
IMAGE = "${imageName}${env.BRANCH_NAME != 'main' ? "-${env.BRANCH_NAME.toLowerCase()}" : ''}:${imageLabel}"
DOCKER_COMPOSE_NAME = "compose-${IMAGE}"
GITLAB_PRIVATE_TOKEN = credentials('isworker-gitlab-api-token')
}
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 {
branch 'main'
}
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 {
branch "main"
}
steps {
dir("deploy") {
sh """#!/usr/bin/env bash
set-new-version configuration.yaml ${GITLAB_PRIVATE_TOKEN} ${GITLAB_ID} ${BUILD_NUMBER} -b staging
"""
}
}
}
}
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}" == 'main') {
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}" == 'main') {
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')
}
}
}