-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJenkinsfile
More file actions
231 lines (194 loc) · 7.14 KB
/
Jenkinsfile
File metadata and controls
231 lines (194 loc) · 7.14 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
pipeline {
agent any
tools {
maven 'Maven-3.6.2'
jdk 'OpenJDK8'
}
options {
timestamps()
disableConcurrentBuilds()
}
environment {
MAVEN_SETTINGS_FILE_ID = 'artifactory-maven-settings'
// Artifactory URLs (container DNS "artifactory" as in your logs)
ARTIFACTORY_BASE_URL = 'http://artifactory:8081/artifactory'
ARTIFACTORY_RELEASE_REPO = 'libs-release-local'
ARTIFACTORY_SNAPSHOT_REPO = 'libs-snapshot-local'
}
stages {
stage('Checkout') {
steps {
checkout scm
}
}
// Testing rule: Only main branch goes through CI. Other branches are ignored.
stage('Guard: testing only main') {
when {
not { anyOf { branch 'master'; branch 'main' } }
}
steps {
script {
echo "Testing CI rule: ignoring branch '${env.BRANCH_NAME}'. Only 'main' branch runs CI."
currentBuild.result = 'NOT_BUILT'
}
}
}
stage('Main: Build') {
when { anyOf { branch 'master'; branch 'main' } }
steps {
withCredentials([
usernamePassword(
credentialsId: 'artifactory-jenkins',
usernameVariable: 'ARTIFACTORY_USERNAME',
passwordVariable: 'ARTIFACTORY_PASSWORD'
)
]) {
configFileProvider([
configFile(fileId: "${MAVEN_SETTINGS_FILE_ID}", variable: 'MAVEN_SETTINGS')
]) {
script {
echo "=== Main branch: BUILD simulator ==="
sh '''
set -euo pipefail
mvn -s "${MAVEN_SETTINGS}" -U clean package
'''
}
}
}
}
}
stage('Main: Integration') {
when { anyOf { branch 'master'; branch 'main' } }
steps {
withCredentials([
usernamePassword(
credentialsId: 'artifactory-jenkins',
usernameVariable: 'ARTIFACTORY_USERNAME',
passwordVariable: 'ARTIFACTORY_PASSWORD'
)
]) {
configFileProvider([
configFile(fileId: "${MAVEN_SETTINGS_FILE_ID}", variable: 'MAVEN_SETTINGS')
]) {
script {
echo "=== Main branch: PARALLEL integration tests ==="
// Split tests-full.txt into two roughly equal parts
sh '''
set -euo pipefail
split -n l/2 tests-full.txt tests-part-
mv tests-part-aa tests-part-1.txt
mv tests-part-ab tests-part-2.txt
'''
parallel(
shard1: {
runSimulatorShard(env.MAVEN_SETTINGS, 'tests-part-1.txt', 'shard1')
},
shard2: {
runSimulatorShard(env.MAVEN_SETTINGS, 'tests-part-2.txt', 'shard2')
}
)
}
}
}
}
}
stage('Main: Publish') {
when { anyOf { branch 'master'; branch 'main' } }
steps {
withCredentials([
usernamePassword(
credentialsId: 'artifactory-jenkins',
usernameVariable: 'ARTIFACTORY_USERNAME',
passwordVariable: 'ARTIFACTORY_PASSWORD'
)
]) {
configFileProvider([
configFile(fileId: "${MAVEN_SETTINGS_FILE_ID}", variable: 'MAVEN_SETTINGS')
]) {
script {
echo "=== Main branch: PUBLISH simulator to Artifactory (skip tests) ==="
sh '''
set -euo pipefail
mvn -s "${MAVEN_SETTINGS}" -U deploy -DskipTests
'''
}
}
}
}
}
}
}
/* ================= FUNCTIONS (below pipeline) ================= */
// Run simulator with telemetry and analytics from Artifactory
// Note: tests-full.txt is in the same repo, so we just copy it
def runSimulatorWithTelemetryAndAnalytics(String mavenSettingsPath) {
// Kept for backward compatibility if needed in other places;
// not used in the new parallel integration flow.
sh """
set -euo pipefail
echo "=== Preparing integration tests (single shard) ==="
cp -f tests-full.txt tests.txt
echo "Using test suite: tests-full.txt"
SIMULATOR_VERSION=\$(mvn -q -s "${mavenSettingsPath}" -DforceStdout help:evaluate -Dexpression=project.version)
SIMULATOR_ARTIFACT=\$(mvn -q -s "${mavenSettingsPath}" -DforceStdout help:evaluate -Dexpression=project.artifactId)
SIMULATOR_JAR="target/\${SIMULATOR_ARTIFACT}-\${SIMULATOR_VERSION}.jar"
if [ ! -f "\${SIMULATOR_JAR}" ]; then
echo "ERROR: Simulator JAR not found: \${SIMULATOR_JAR}"
exit 1
fi
rm -rf deps
mkdir -p deps
echo "=== Downloading telemetry and analytics from Artifactory ==="
mvn -s "${mavenSettingsPath}" -U dependency:copy -Dtransitive=false \\
-Dartifact=com.lidar:telemetry:99-SNAPSHOT:jar \\
-DoutputDirectory=deps
mvn -s "${mavenSettingsPath}" -U dependency:copy -Dtransitive=false \\
-Dartifact=com.lidar:analytics:99-SNAPSHOT:jar \\
-DoutputDirectory=deps
TELEMETRY_JAR=\$(ls -1 deps/telemetry-*.jar | head -n 1)
ANALYTICS_JAR=\$(ls -1 deps/analytics-*.jar | head -n 1)
if [ -z "\${TELEMETRY_JAR}" ] || [ -z "\${ANALYTICS_JAR}" ]; then
echo "ERROR: Could not find telemetry or analytics JARs"
ls -la deps || true
exit 1
fi
echo "=== Running simulator (single shard) ==="
java -cp "\${SIMULATOR_JAR}:\${TELEMETRY_JAR}:\${ANALYTICS_JAR}" com.lidar.simulation.Simulator
echo "Integration tests PASSED."
"""
}
def runSimulatorShard(String mavenSettingsPath, String testsFile, String shardName) {
dir("it-${shardName}") {
sh """
set -euo pipefail
echo "=== [${shardName}] Preparing tests from ${testsFile} ==="
cp -f "../${testsFile}" tests.txt
test -f "tests.txt"
SIMULATOR_VERSION=\$(mvn -q -s "${mavenSettingsPath}" -f .. -DforceStdout help:evaluate -Dexpression=project.version)
SIMULATOR_ARTIFACT=\$(mvn -q -s "${mavenSettingsPath}" -f .. -DforceStdout help:evaluate -Dexpression=project.artifactId)
SIMULATOR_JAR="../target/\${SIMULATOR_ARTIFACT}-\${SIMULATOR_VERSION}.jar"
if [ ! -f "\${SIMULATOR_JAR}" ]; then
echo "ERROR: Simulator JAR not found: \${SIMULATOR_JAR}"
exit 1
fi
rm -rf deps
mkdir -p deps
echo "=== [${shardName}] Downloading telemetry and analytics from Artifactory ==="
mvn -s "${mavenSettingsPath}" -U dependency:copy -Dtransitive=false \\
-Dartifact=com.lidar:telemetry:99-SNAPSHOT:jar \\
-DoutputDirectory=deps
mvn -s "${mavenSettingsPath}" -U dependency:copy -Dtransitive=false \\
-Dartifact=com.lidar:analytics:99-SNAPSHOT:jar \\
-DoutputDirectory=deps
TELEMETRY_JAR=\$(ls -1 deps/telemetry-*.jar | head -n 1)
ANALYTICS_JAR=\$(ls -1 deps/analytics-*.jar | head -n 1)
if [ -z "\${TELEMETRY_JAR}" ] || [ -z "\${ANALYTICS_JAR}" ]; then
echo "ERROR: Could not find telemetry or analytics JARs"
ls -la deps || true
exit 1
fi
echo "=== [${shardName}] Running simulator ==="
java -cp "\${SIMULATOR_JAR}:\${TELEMETRY_JAR}:\${ANALYTICS_JAR}" com.lidar.simulation.Simulator
"""
}
}