-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJenkinsfile
More file actions
175 lines (158 loc) · 5.32 KB
/
Jenkinsfile
File metadata and controls
175 lines (158 loc) · 5.32 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
library(
identifier: 'jenkins-lib-common@1.3.3',
retriever: modernSCM([
$class : 'GitSCMSource',
credentialsId: 'jenkins-integration-with-github-account',
remote : 'git@github.com:zextras/jenkins-lib-common.git'
])
)
boolean isBuildingTag() {
return env.TAG_NAME ? true : false
}
String profile = isBuildingTag() ? '-Pprod' : ''
properties(defaultPipelineProperties())
pipeline {
agent {
node {
label 'zextras-v1'
}
}
environment {
MVN_OPTS = "-Ddebug=0 ${profile}"
GITHUB_BOT_PR_CREDS = credentials('jenkins-integration-with-github-account')
JAVA_OPTS = '-Dfile.encoding=UTF8'
LC_ALL = 'C.UTF-8'
}
options {
buildDiscarder(logRotator(numToKeepStr: '25'))
skipDefaultCheckout()
timeout(time: 2, unit: 'HOURS')
}
triggers {
cron(env.BRANCH_NAME == 'devel' ? 'H 5 * * *' : '')
}
stages {
stage('Setup') {
steps {
checkout scm
script {
gitMetadata()
}
}
}
stage('Build') {
steps {
container('jdk-21') {
sh "mvn ${MVN_OPTS} clean install -DskipTests"
}
}
}
stage('Test') {
steps {
container('jdk-21') {
sh "mvn ${MVN_OPTS} verify"
junit allowEmptyResults: true,
testResults: '**/target/surefire-reports/*.xml,**/target/failsafe-reports/*.xml'
}
}
}
stage('Sonarqube Analysis') {
steps {
container('jdk-21') {
withSonarQubeEnv(credentialsId: 'sonarqube-user-token', installationName: 'SonarQube instance') {
sh """
mvn ${MVN_OPTS} -DskipTests \
sonar:sonar \
-Dsonar.junit.reportPaths=target/surefire-reports,target/failsafe-reports
"""
}
}
}
}
stage('Publish SNAPSHOT to maven') {
when {
not { buildingTag() }
}
steps {
container('jdk-21') {
withCredentials([file(credentialsId: 'jenkins-maven-settings.xml', variable: 'SETTINGS_PATH')]) {
script {
sh "mvn ${MVN_OPTS} -s " + SETTINGS_PATH + " deploy -DskipTests=true"
}
}
}
}
}
stage('Publish to maven') {
when {
buildingTag()
}
steps {
container('jdk-21') {
withCredentials([file(credentialsId: 'jenkins-maven-settings.xml', variable: 'SETTINGS_PATH')]) {
script {
sh "mvn ${MVN_OPTS} -s " + SETTINGS_PATH + " deploy -Dchangelist= -DskipTests=true"
}
}
}
}
}
stage('Publish containers') {
when {
expression {
return isBuildingTag() || env.BRANCH_NAME == 'devel'
}
}
steps {
container('dind') {
withDockerRegistry(credentialsId: 'private-registry', url: 'https://registry.dev.zextras.com') {
script {
Set<String> tagVersions = []
if (isBuildingTag()) {
tagVersions = [env.TAG_NAME, 'stable']
} else {
tagVersions = ['devel', 'latest']
}
dockerHelper.buildImage([
dockerfile: 'docker/openldap/Dockerfile',
imageName : 'registry.dev.zextras.com/dev/carbonio-openldap',
imageTags : tagVersions,
ocLabels : [
title : 'Carbonio OpenLDAP',
descriptionFile: 'docker/openldap/description.md',
version : tagVersions[0]
]
])
}
}
}
}
}
stage('Build deb/rpm') {
steps {
echo 'Building deb/rpm packages'
buildStage()
}
}
stage('Upload artifacts') {
when {
expression { return uploadStage.shouldUpload() }
}
tools {
jfrog 'jfrog-cli'
}
steps {
uploadStage(
packages: yapHelper.resolvePackageNames('yap.json')
)
}
}
stage('Bump version') {
steps {
script {
dt2_semanticRelease()
}
}
}
}
}