-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJenkinsfile
More file actions
179 lines (166 loc) · 6.21 KB
/
Jenkinsfile
File metadata and controls
179 lines (166 loc) · 6.21 KB
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
#!groovy
def app
def imageName="fbi-api-gateway"
def imageLabel=BUILD_NUMBER
pipeline {
agent {
label 'devel11'
}
triggers{
// @TODO parameters on githubPush .. eg. branch
githubPush()
upstream(
upstreamProjects: env.BRANCH_NAME == "master" ? 'Docker-base-node-bump-trigger' : ''
)
}
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"
SONAR_SCANNER_HOME = tool 'SonarQube Scanner from Maven Central'
SONAR_SCANNER = "$SONAR_SCANNER_HOME/bin/sonar-scanner"
SONAR_PROJECT_KEY = "fbi-api"
SONAR_SOURCES='./'
SONAR_TESTS='./'
}
stages {
stage("SonarQube") {
steps {
withSonarQubeEnv(installationName: 'sonarqube.dbc.dk') {
script {
def sonarOptions = ""
sonarOptions += " -Dsonar.branch.name=$BRANCH_NAME"
if (env.BRANCH_NAME != 'master') {
sonarOptions += " -Dsonar.newCode.referenceBranch=master"
}
sonarOptions += " -Dsonar.exclusions=**/__tests__/**,**/*.test.js,**/*.test.ts"
sonarOptions += " -Dsonar.test.exclusions=**/__tests__/**,**/*.test.js,**/*.test.ts"
sonarOptions += " -Dsonar.coverage.exclusions=**/__tests__/**,**/*.test.js,**/*.test.ts"
sh returnStatus: true, script: """
$SONAR_SCANNER $sonarOptions -Dsonar.token=${SONAR_AUTH_TOKEN} -Dsonar.projectKey="${SONAR_PROJECT_KEY}"
"""
}
}
}
}
stage("Quality gate") {
steps {
// wait for analysis results
timeout(time: 1, unit: 'HOURS') {
waitForQualityGate abortPipeline: true
}
}
}
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 'devel11'
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 'devel11'
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')
}
//Trigger a build for studiesoeg to ensure there is no breaking changes in the API
if ("${env.BRANCH_NAME}" == 'prod') {
build job: 'studiesoeg-build/main', wait: false
}
}
}
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')
}
}
}