-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathJenkinsfile
More file actions
222 lines (203 loc) · 9.57 KB
/
Jenkinsfile
File metadata and controls
222 lines (203 loc) · 9.57 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
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
def IMPORTANT_BRANCH_OR_TAG = (env.BRANCH_NAME =~ /(develop|master_.*)/).matches() || env.TAG_NAME != null
pipeline {
agent {
label 'build'
}
environment {
M2_REPO = "${HOME}/.m2"
CI = credentials("app-jenkins")
SERVICE_GIT_URL = credentials("service-gitlab-url")
SERVICE_NEXUS_URL = credentials("service-nexus-url")
SERVICE_REPO_SSHURL = credentials("repository-connection-string")
SERVICE_REPOSITORY_URL = credentials("service-repository-url")
}
options {
timeout(time: 4, unit: 'HOURS')
disableConcurrentBuilds()
buildDiscarder(
logRotator(
artifactDaysToKeepStr: '',
artifactNumToKeepStr: '',
numToKeepStr: '100'
)
)
}
parameters {
choice(name: 'GOAL', choices: ['publish', 'deploy', 'build'], description: '- "build" only builds the artifacts\n- "deploy" builds and pushes the artifacts in Nexus\n- "publish" deploys and pushes the .deb/.rpm to the repository')
booleanParam(name: 'DO_CHECKS_AND_TESTS', defaultValue: IMPORTANT_BRANCH_OR_TAG, description: 'Tick the box to run checks and tests')
}
tools {
jdk 'java21' // java11 || java17 || java21
maven 'maven-3.9' // maven-3.8 || maven-3.9
}
stages {
stage('Ask for build execution (when parameters are not defined)') {
agent none
when { expression { env.DO_CHECKS_AND_TESTS == null } }
steps {
script {
INPUT_PARAMS = input message: 'Configure your build',
parameters: [
choice(name: 'GOAL', choices: 'publish\ndeploy\nbuild', defaultValue: 'publish', description: '- "build" only builds the artifacts\n- "deploy" builds and pushes the artifacts in Nexus\n- "publish" deploys and pushes the .deb/.rpm to the repository'),
booleanParam(name: 'DO_CHECKS_AND_TESTS', defaultValue: IMPORTANT_BRANCH_OR_TAG, description: 'Tick the box to run checks and tests'),
]
env.GOAL = INPUT_PARAMS.GOAL
env.DO_CHECKS_AND_TESTS = INPUT_PARAMS.DO_CHECKS_AND_TESTS
}
}
}
stage('Show Configuration') {
steps {
script {
if (env.GOAL == 'build') {
// If the goal is only to build, we only run "mvn verify" (includes running tests, except if explicitely skipped)
env.MVN_GOAL = 'verify'
} else {
// Otherwise, we run "mvn deploy" to generate the artifact and upload it to Nexus
env.MVN_GOAL = 'deploy'
}
env.MVN_COMMAND = "mvn --settings ${pwd()}/.ci/settings.xml --show-version --batch-mode --errors -DdeployAtEnd=true"
if (env.DO_CHECKS_AND_TESTS == 'false') {
// If checks and tests are disabled:
// - "-T1C" builds modules in parallel
// - "-Dspotless.check.skip=true" skips executing spotless
// - "-DskipTests=true" skips executing tests. Do NOT use "-Dmaven.test.skip" instead as it also doesn't build the test jars that are used in dependency in some modules
// - "-Dlicense.skip" skips checking license headers
env.MVN_COMMAND = "${env.MVN_COMMAND} -T1C -Dspotless.check.skip=true -DskipTests=true -Dlicense.skip=true"
}
def pom = readMavenPom file: 'pom.xml'
env.POM_VERSION = pom.version
}
echo "IMPORTANT_BRANCH_OR_TAG = ${env.IMPORTANT_BRANCH_OR_TAG}"
echo "GOAL = ${env.GOAL}"
echo "MVN_GOAL = ${env.MVN_GOAL}"
echo "DO_CHECKS_AND_TESTS = ${env.DO_CHECKS_AND_TESTS}"
echo "MVN_COMMAND = ${env.MVN_COMMAND}"
echo "POM_VERSION = ${env.POM_VERSION}"
}
}
stage('Upgrade build context') {
steps {
sh 'sudo apt install -y build-essential make ruby ruby-dev rubygems jq'
sh 'sudo timedatectl set-timezone Europe/Paris'
sh 'sudo gem install fpm'
nvm('v22.22.0') { // We're installing correct Node version through NVM then update the path to make it available. Do NOT wrap your code in `nvm('...') {}` as it would override the whole PATH and then break tools (jdk, maven) configurations
script {
nvmPath = sh(script: 'dirname $(which node)', returnStdout: true).trim()
env.PATH = "${nvmPath}:${env.PATH}"
}
}
}
}
stage('Parallel') {
parallel {
stage('Check icomoon') {
when {
environment(name: 'DO_CHECKS_AND_TESTS', value: 'true')
}
steps {
sh './tools/check_icomoon.sh'
}
}
stage('Frontend') {
steps {
dir('ui/ui-frontend') {
script {
sh 'npm ci'
if (env.DO_CHECKS_AND_TESTS == 'true') {
sh 'npm run lint'
}
sh 'npm run build:vitamui-library'
sh 'npm run build:allModules'
if (env.DO_CHECKS_AND_TESTS == 'true') {
sh 'npm run ci:test'
}
if (env.GOAL == 'publish') {
// If the goal is to publish, we also generate .deb/.rpm
sh '../../tools/packaging/package-fronts.sh ui-identity,ui-archive-search,ui-portal,ui-pastis,ui-collect,ui-referential,ui-ingest,ui-design-system ${POM_VERSION}'
}
}
}
}
}
stage('Backend') {
steps {
// TODO: generate .deb/.rpm by running Makefile directly in the Jenkinsfile instead of being run by a maven plugin
sh '${MVN_COMMAND} clean ${MVN_GOAL} -U -Pvitam,deb,rpm'
}
}
}
post {
always {
script {
if (env.DO_CHECKS_AND_TESTS == 'true') {
junit '**/target/surefire-reports/*.xml'
junit '**/target/junit/*.xml'
}
}
}
}
}
// If in "deploy" or "publish" mode, build pastis front in "standalone" mode & run maven goal to package the .exe/.zip
stage("Pastis standalone") {
when {
anyOf {
environment(name: 'GOAL', value: 'deploy')
environment(name: 'GOAL', value: 'publish')
}
}
steps {
dir('ui/ui-frontend') {
sh 'npm run build:pastis-standalone'
}
sh '${MVN_COMMAND} deploy -Pstandalone --projects "api/api-pastis/pastis-standalone" -Dspotless.check.skip=true -Dmaven.test.skip -Dlicense.skip=true'
}
}
stage("Publish") {
when {
environment(name: 'GOAL', value: 'publish')
}
steps {
script {
checkout([$class : 'GitSCM',
branches : [[name: 'scaleway_j11']],
doGenerateSubmoduleConfigurations: false,
extensions : [[$class: 'RelativeTargetDirectory', relativeTargetDir: 'vitam-build.git']],
submoduleCfg : [],
userRemoteConfigs : [[credentialsId: 'app-jenkins', url: "$SERVICE_GIT_URL"]]
])
sshagent(credentials: ['jenkins_sftp_to_repository']) {
sh 'vitam-build.git/push_vitamui_repo.sh contrib ${SERVICE_REPO_SSHURL} rpm'
sh 'vitam-build.git/push_vitamui_repo.sh contrib ${SERVICE_REPO_SSHURL} deb'
}
}
}
}
stage("Update symlink") {
when {
anyOf {
branch "develop"
branch "master_*"
tag pattern: "^[1-9]+(\\.rc)?(\\.[0-9]+)?\\.[0-9]+(-.*)?", comparator: "REGEXP"
}
environment(name: 'GOAL', value: 'publish')
}
steps {
sshagent(credentials: ['jenkins_sftp_to_repository']) {
sh 'vitam-build.git/push_symlink_repo.sh contrib ${SERVICE_REPO_SSHURL}'
}
}
}
}
post {
// Clean after build
always {
// Cleanup any remaining docker volumes
sh 'docker volume prune -f'
// Cleanup M2 repo
sh 'rm -fr ${M2_REPO}/repository/fr/gouv/vitamui/'
// Cleanup workspace
cleanWs()
}
}
}