-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
225 lines (215 loc) · 8.03 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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
#!groovy
String docker_images_log_stash_tag = "docker_images_log"
String workerNode = "devel11"
Boolean DEPLOY_TO_STAGING_CANDIDATE=false
Boolean FAST_BUILD=false
//Byg!
pipeline {
agent { label workerNode }
tools {
jdk 'jdk17'
maven 'Maven 3'
}
environment {
MAVEN_OPTS = "-Dmaven.repo.local=/home/isworker/.m2/dataio-repo -XX:+TieredCompilation -XX:TieredStopAtLevel=1 -Dorg.slf4j.simpleLogger.showThreadName=true -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn"
ARTIFACTORY_LOGIN = credentials("artifactory_login")
GITLAB_PRIVATE_TOKEN = credentials("metascrum-gitlab-api-token")
BUILD_NUMBER = "${env.BUILD_NUMBER}"
DEPLOY_ARTIFACTS = "commons/utils/flow-store-service-connector, \
commons/utils/tickle-harvester-service-connector, \
harvester/framework, \
gatekeeper, \
harvester/utils/rawrepo-connector, \
harvester/utils/harvester-job-builder, \
commons/utils, \
commons/utils/binary-file-store, \
cli/acc-test-runner, \
cli/flow-test-runner"
SONAR_SCANNER_HOME = tool 'SonarQube Scanner from Maven Central'
SONAR_SCANNER = "$SONAR_SCANNER_HOME/bin/sonar-scanner"
SONAR_PROJECT_KEY = "dataio"
SONAR_SOURCES="src"
SONAR_TESTS="test"
}
triggers {
upstream(upstreamProjects: "Docker-payara6-bump-trigger",
threshold: hudson.model.Result.SUCCESS)
}
options {
skipDefaultCheckout(true)
buildDiscarder(logRotator(artifactDaysToKeepStr: "",
artifactNumToKeepStr: "", daysToKeepStr: "30", numToKeepStr: "30"))
timestamps()
timeout(time: 1, unit: "HOURS")
disableConcurrentBuilds(abortPrevious: true)
lock('dataio-build')
}
stages {
stage('clean and checkout') {
steps {
cleanWs()
sh """
test -d /home/isworker/.m2/dataio-repo/dk/dbc && rm -r /home/isworker/.m2/dataio-repo/dk/dbc || echo ok
"""
checkout scm
script {
DEPLOY_TO_STAGING_CANDIDATE |= sh(
returnStatus: true,
script: """#!/bin/bash
git log -1 | tail +5 | grep -E ' *!'
"""
) == 0
}
script {
FAST_BUILD |= sh(
returnStatus: true,
script: """#!/bin/bash
git log -1 | tail +5 | grep -E ' *!!'
"""
) == 0
}
}
}
stage("build") {
steps {
sh """#!/bin/bash
FAST=""
echo FAST: ${FAST_BUILD}
if [ "master" != "${env.BRANCH_NAME}" ] && [ ${FAST_BUILD} -eq "true" ]; then
echo Fast branch deployment skip all tests
FAST=" -P !integration-test -Dmaven.test.skip=true "
fi
mvn -B -T 4 \${FAST} -Dtag="${env.BRANCH_NAME}-${env.BUILD_NUMBER}" install || exit 1
if [ -n "\${FAST}" ]; then
echo Run PMD
mvn -B -T 6 -P !integration-test pmd:pmd
fi
"""
script {
junit allowEmptyResults: true, testResults: '**/target/*-reports/*.xml'
def java = scanForIssues tool: [$class: 'Java']
publishIssues issues: [java], unstableTotalAll: 10
def pmd = scanForIssues tool: [$class: 'Pmd']
publishIssues issues: [pmd], unstableTotalAll: 1
archiveArtifacts artifacts: "cli/acceptance-test/target/dataio-cli-acctest.jar,gatekeeper/target/dataio-gatekeeper*.jar,cli/dataio-cli",
fingerprint: true
}
}
}
stage("sonarqube") {
when {
anyOf {
branch "master"
expression { return !FAST_BUILD}
}
}
steps {
withSonarQubeEnv(installationName: 'sonarqube.dbc.dk') {
script {
// first run actual build
def status = 0
// then trigger sonarqube analysis
def sonarOptions = "-Dsonar.branch.name=${BRANCH_NAME}"
if (env.BRANCH_NAME != 'master') {
sonarOptions += " -Dsonar.newCode.referenceBranch=master"
}
// for java/maven projects
status += sh returnStatus: true, script: """
mvn -B $sonarOptions sonar:sonar
"""
if (status != 0) {
error("build failed")
}
}
}
}
}
stage("deploy to mavenrepo.dbc.dk") {
when {
branch "master"
}
steps {
sh """
mvn install -T 3 -B -Dmaven.test.skip=true -Pdocker-push
mvn deploy -T 6 -B -Dmaven.test.skip=true -Ddocker.skip=true -pl "${DEPLOY_ARTIFACTS}" -am
"""
}
}
stage("Clean up docker images") {
when {
branch "master"
}
steps {
sh """
./docker/remove-images docker-metascrum.artifacts.dbccloud.dk/dbc-payara-*
./docker/remove-images docker-metascrum.artifacts.dbccloud.dk/dataio-*
"""
}
}
stage("Update staging config") {
when {
branch "master"
}
steps {
script {
sh """
java -jar buildstuff/target/buildstuff.jar version dataio.xml -t ${env.GITLAB_PRIVATE_TOKEN} -v DIT-${env.BUILD_NUMBER}
"""
}
}
}
stage("Update dit config") {
when {
branch "master"
}
steps {
script {
sh """
java -jar buildstuff/target/buildstuff.jar version dataio.xml -n d -t ${env.GITLAB_PRIVATE_TOKEN} -v DIT-${env.BUILD_NUMBER}
"""
}
}
}
stage("Build branch artifacts for staging") {
when {
not {
branch "master"
}
}
steps {
script {
if (DEPLOY_TO_STAGING_CANDIDATE) {
sh """
echo "Gogo staging gadget!!!"
mvn install -B -T 3 -Dmaven.test.skip=true -Pdocker-push -Dtag="${env.BRANCH_NAME}-${env.BUILD_NUMBER}"
mvn deploy -T 6 -B -Dmaven.test.skip=true -Ddocker.skip=true -pl "${DEPLOY_ARTIFACTS}"
"""
}
}
}
}
stage("Deploy branch to staging") {
when {
not {
branch "master"
}
}
steps {
script {
if (DEPLOY_TO_STAGING_CANDIDATE) {
sh """
echo "Gogo version gadget!!!"
java -jar buildstuff/target/buildstuff.jar version dataio.xml -t ${env.GITLAB_PRIVATE_TOKEN} -v ${env.BRANCH_NAME}-${env.BUILD_NUMBER}
"""
}
}
}
}
}
post {
always {
echo 'Cleaning up'
cleanWs()
}
}
}