Repository navigation
Expand file tree
/
Copy pathJenkinsfile
More file actions
233 lines (213 loc) · 7.5 KB
/
Copy pathJenkinsfile
File metadata and controls
233 lines (213 loc) · 7.5 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
223
224
225
226
227
228
229
230
231
232
233
/*
* (C) Copyright 2020-2025 Nuxeo (http://nuxeo.com/) and others.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Contributors:
* Antoine Taillefer <ataillefer@nuxeo.com>
*/
library identifier: "platform-ci-shared-library@v0.0.75"
def getFirstBuildCause(String className) {
def upstreamCauses = currentBuild.getBuildCauses(className) ?: []
if (!upstreamCauses.isEmpty()) {
return upstreamCauses[0]
}
return null
}
def hasUpstream() {
return !currentBuild.upstreamBuilds.isEmpty()
}
def hasNuxeoVersionParameter() {
return params.NUXEO_VERSION?.trim()
}
def hasGitHubStatusParameters() {
return params.GITHUB_STATUS_REPOSITORY_URL?.trim() && params.GITHUB_STATUS_COMMIT_SHA?.trim()
}
def isTriggered() {
return getFirstBuildCause('org.jenkinsci.plugins.workflow.support.steps.build.BuildUpstreamCause') != null
}
def isTriggeredByNuxeoPR() {
def upstreamCause = getFirstBuildCause('org.jenkinsci.plugins.workflow.support.steps.build.BuildUpstreamCause')
return upstreamCause?.upstreamProject?.contains('PR-')
}
def mustNotifyBuildStatus() {
return !isTriggeredByNuxeoPR() && !(env.NUXEO_VERSION ==~ /^.+PR-.+$/)
}
def upstreamJobName = hasUpstream() ? currentBuild.upstreamBuilds[0].getFullProjectName() : null
def upstreamBuildNumber = hasUpstream() ? currentBuild.upstreamBuilds[0].getNumber() : null
pipeline {
agent {
label "jenkins-nodejs"
}
options {
buildDiscarder(logRotator(daysToKeepStr: '60', numToKeepStr: '60', artifactNumToKeepStr: '5'))
githubProjectProperty(projectUrlStr: 'https://github.com/nuxeo/rest-api-compatibility-tests/')
}
parameters {
string(name: 'NUXEO_VERSION', defaultValue: '', description: 'Version of the Nuxeo server image, defaults to 2021.x.')
hidden(name: 'GITHUB_STATUS_REPOSITORY_URL', defaultValue: '', description: 'GitHub repository of the nuxeo project.')
hidden(name: 'GITHUB_STATUS_COMMIT_SHA', defaultValue: '', description: 'Git commit sha of the nuxeo/lts/nuxeo upstream build.')
}
environment {
NUXEO_DOCKER_REPOSITORY = "${isTriggered() ? DOCKER_REGISTRY : PRIVATE_DOCKER_REGISTRY}/nuxeo/nuxeo"
NUXEO_VERSION = "${hasNuxeoVersionParameter() ? params.NUXEO_VERSION : '2023.x'}"
NUXEO_LTS_JOB = 'nuxeo/lts/nuxeo'
NAMESPACE = "nuxeo-rest-api-tests-$BRANCH_NAME-$BUILD_NUMBER".toLowerCase()
}
stages {
stage('Set labels') {
steps {
container('nodejs') {
script {
nxK8s.setPodLabels()
}
}
}
}
stage('Build info') {
steps {
script {
def buildInfo = """
----------------------------------------
Build information
----------------------------------------
Branch: ${BRANCH_NAME}
"""
if (isTriggered()) {
if (hasUpstream()) {
buildInfo += """
Triggered by: ${upstreamJobName} #${upstreamBuildNumber}
"""
} else {
buildInfo += """
Originally triggered by a ${NUXEO_LTS_JOB} upstream build.
"""
}
buildInfo += """
With parameter NUXEO_VERSION: ${params.NUXEO_VERSION}
"""
} else {
buildInfo += """
Not triggered by an upstream job.
"""
}
if (hasGitHubStatusParameters()) {
buildInfo += """
GITHUB_STATUS_REPOSITORY_URL: ${params.GITHUB_STATUS_REPOSITORY_URL}
GITHUB_STATUS_COMMIT_SHA: ${params.GITHUB_STATUS_COMMIT_SHA}
"""
}
echo buildInfo
}
}
}
stage('npm/ESLint') {
// set GitHub status check only on the REST API tests repository, not on the nuxeo repository when triggered
steps {
script {
if (!isTriggered()) {
nxGitHub.setStatus(context: 'npm/eslint', message: 'Install npm dependencies and run ESLint', state: 'PENDING')
}
container('nodejs') {
echo """
----------------------------------------
Install npm dependencies and run ESLint
----------------------------------------"""
def nodeVersion = sh(script: 'node -v', returnStdout: true).trim()
echo "node version: ${nodeVersion}"
sh 'npm ci'
sh 'npm run lint'
}
}
}
post {
success {
script {
if (!isTriggered()) {
nxGitHub.setStatus(context: 'npm/eslint', message: 'Install npm dependencies and run ESLint', state: 'SUCCESS')
}
}
}
failure {
script {
if (!isTriggered()) {
nxGitHub.setStatus(context: 'npm/eslint', message: 'Install npm dependencies and run ESLint', state: 'FAILURE')
}
}
}
}
}
stage('Run REST API tests') {
steps {
script {
def nuxeoHelmfileRef = nxDocker.getLabel(image: "${NUXEO_DOCKER_REPOSITORY}:${NUXEO_VERSION}", label: 'org.nuxeo.scm-ref')
nxWithGitHubStatus(context: 'restapitests', message: 'Run REST API tests', state: 'PENDING') {
container('nodejs') {
echo """
-------------------------------------------------------
Run REST API tests against:
- ${NUXEO_DOCKER_REPOSITORY}:${NUXEO_VERSION}
- MongoDB
- Elasticsearch
- Kafka
-------------------------------------------------------"""
nxWithHelmfileDeployment(namespace: env.NAMESPACE, envVars: [
"NUXEO_HELMFILE_REF=${nuxeoHelmfileRef}",
"NUXEO_SERVER_URL=http://nuxeo.${NAMESPACE}.svc.cluster.local/nuxeo",
]) {
echo """
------------------
Run REST API tests
------------------"""
sh 'npm test'
}
}
}
}
}
}
}
post {
always {
script {
if (isTriggered()) {
def upstream = hasUpstream() ? "${upstreamJobName} #${upstreamBuildNumber}" : "${NUXEO_LTS_JOB}"
currentBuild.description = "Upstream: ${upstream}"
}
if (!isTriggered()) {
nxJira.updateIssues()
}
if (mustNotifyBuildStatus()) {
nxUtils.callIfBuildRecoverOrFail(
success: {
nxTeams.success(
message: "Successfully built ${currentBuild.fullProjectName}",
changes: true,
)},
error: {
nxTeams.error(
message: "Failed to build ${currentBuild.fullProjectName}",
changes: true,
culprits: true,
)},
buildGroupComputer: {
build ->
def versionParameter = nxBuildWrapper(build).getParameterValue("NUXEO_VERSION") ?: '2023.0'
return nxUtils.getMajorVersion(version: versionParameter)
}
)
}
}
}
}
}