forked from elastic/apm-integration-testing
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfileAxis
270 lines (258 loc) · 8.13 KB
/
JenkinsfileAxis
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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
#!/usr/bin/env groovy
@Library('apm@current') _
import co.elastic.matrix.*
import groovy.transform.Field
/**
This is the parallel tasks generator,
it is need as field to store the results of the tests.
*/
@Field def integrationTestsGen
/**
YAML files to get agent versions and exclusions.
*/
@Field Map ymlFiles = [
'go': 'tests/versions/go.yml',
'java': 'tests/versions/java.yml',
'nodejs': 'tests/versions/nodejs.yml',
'python': 'tests/versions/python.yml',
'ruby': 'tests/versions/ruby.yml',
'rum': 'tests/versions/rum.yml',
'server': 'tests/versions/apm_server.yml'
]
/**
Key which contains the agent versions.
*/
@Field Map agentYamlVar = [
'go': 'GO_AGENT',
'java': 'JAVA_AGENT',
'nodejs': 'NODEJS_AGENT',
'python': 'PYTHON_AGENT',
'ruby': 'RUBY_AGENT',
'rum': 'RUM_AGENT',
'server': 'APM_SERVER'
]
/**
translate from human agent name to an ID.
*/
@Field Map mapAgentsIDs = [
'Go': 'go',
'Java': 'java',
'Node.js': 'nodejs',
'Python': 'python',
'Ruby': 'ruby',
'RUM': 'rum',
'All': 'all'
]
pipeline {
agent { label 'linux && immutable' }
environment {
BASE_DIR="src/github.com/elastic/apm-integration-testing"
REPO="[email protected]:elastic/apm-integration-testing.git"
NOTIFY_TO = credentials('notify-to')
JOB_GCS_BUCKET = credentials('gcs-bucket')
JOB_GIT_CREDENTIALS = "f6c7695a-671e-4f4f-a331-acdce44ff9ba"
PIPELINE_LOG_LEVEL = 'INFO'
DISABLE_BUILD_PARALLEL = "${params.DISABLE_BUILD_PARALLEL}"
}
options {
timeout(time: 1, unit: 'HOURS')
buildDiscarder(logRotator(numToKeepStr: '300', artifactNumToKeepStr: '300', daysToKeepStr: '30'))
timestamps()
ansiColor('xterm')
disableResume()
durabilityHint('PERFORMANCE_OPTIMIZED')
}
parameters {
choice(name: 'agent_integration_test', choices: ['Go', 'Java', 'Node.js', 'Python', 'Ruby', 'RUM', 'All'], description: 'Name of the APM Agent you want to run the integration tests.')
string(name: 'ELASTIC_STACK_VERSION', defaultValue: "7.0.0", description: "Elastic Stack Git branch/tag to use")
string(name: 'INTEGRATION_TESTING_VERSION', defaultValue: "master", description: "Integration testing Git branch/tag to use")
string(name: 'BUILD_OPTS', defaultValue: "", description: "Addicional build options to passing compose.py")
string(name: 'UPSTREAM_BUILD', defaultValue: "", description: "upstream build info to show in the description.")
booleanParam(name: 'DISABLE_BUILD_PARALLEL', defaultValue: true, description: "Disable the build parallel option on compose.py, disable it is better for error detection.")
}
stages{
/**
Checkout the code and stash it, to use it on other stages.
*/
stage('Checkout'){
options { skipDefaultCheckout() }
steps {
deleteDir()
dir("${BASE_DIR}"){
checkout([$class: 'GitSCM',
branches: [[name: "${params.INTEGRATION_TESTING_VERSION}"]],
doGenerateSubmoduleConfigurations: false,
extensions: [],
submoduleCfg: [],
userRemoteConfigs: [[
refspec: '+refs/heads/*:refs/remotes/origin/* +refs/pull/*/head:refs/remotes/origin/pr/*',
url: "${REPO}",
credentialsId: "${JOB_GIT_CREDENTIALS}"]]
])
}
stash allowEmpty: true, name: 'source', useDefaultExcludes: false
script{
currentBuild.displayName = "apm-agent-${params.agent_integration_test} - ${currentBuild.displayName}"
currentBuild.description = "Agent ${params.agent_integration_test} - ${params.UPSTREAM_BUILD}"
}
}
}
/**
launch integration tests.
*/
stage("Integration Tests"){
when {
expression { return params.agent_integration_test != 'All' }
}
steps {
deleteDir()
unstash "source"
dir("${BASE_DIR}"){
script {
def agentTests = mapAgentsIDs[params.agent_integration_test]
integrationTestsGen = new IntegrationTestingParallelTaskGenerator(
xKey: agentYamlVar[agentTests],
yKey: agentYamlVar['server'],
xFile: ymlFiles[agentTests],
yFile: ymlFiles['server'],
exclusionFile: ymlFiles[agentTests],
tag: agentTests,
name: params.agent_integration_test,
steps: this
)
def mapPatallelTasks = integrationTestsGen.generateParallelTests()
parallel(mapPatallelTasks)
}
}
}
}
stage("All") {
when {
expression { return params.agent_integration_test == 'All' }
}
environment {
TMPDIR = "${WORKSPACE}"
REUSE_CONTAINERS = "true"
}
steps {
deleteDir()
unstash "source"
dir("${BASE_DIR}"){
sh "./scripts/ci/all.sh"
}
}
post {
always {
wrappingup('all')
}
}
}
}
post {
always{
script{
if(integrationTestsGen?.results){
writeJSON(file: 'results.json', json: toJSON(integrationTestsGen.results), pretty: 2)
def mapResults = ["${params.agent_integration_test}": integrationTestsGen.results]
def processor = new ResultsProcessor()
processor.processResults(mapResults)
archiveArtifacts allowEmptyArchive: true, artifacts: 'results.json,results.html', defaultExcludes: false
}
}
}
success {
echoColor(text: '[SUCCESS]', colorfg: 'green', colorbg: 'default')
}
aborted {
echoColor(text: '[ABORTED]', colorfg: 'magenta', colorbg: 'default')
}
failure {
echoColor(text: '[FAILURE]', colorfg: 'red', colorbg: 'default')
step([$class: 'Mailer', notifyEveryUnstableBuild: true, recipients: "${NOTIFY_TO}", sendToIndividuals: false])
}
unstable {
echoColor(text: '[UNSTABLE]', colorfg: 'yellow', colorbg: 'default')
}
}
}
/**
Parallel task generator for the integration tests.
*/
class IntegrationTestingParallelTaskGenerator extends DefaultParallelTaskGenerator {
/**
Enviroment variable to put the agent version before run tests.
*/
public Map agentEnvVar = [
'go': 'APM_AGENT_GO_VERSION',
'java': 'APM_AGENT_JAVA_VERSION',
'nodejs': 'APM_AGENT_NODEJS_VERSION',
'python': 'APM_AGENT_PYTHON_VERSION',
'ruby': 'APM_AGENT_RUBY_VERSION',
'rum': 'APM_AGENT_RUM_VERSION',
'server': 'APM_SERVER_BRANCH'
]
public IntegrationTestingParallelTaskGenerator(Map params){
super(params)
}
/**
build a clousure that launch and agent and execute the corresponding test script,
then store the results.
*/
public Closure generateStep(x, y){
return {
steps.node('linux && immutable'){
def env = ["APM_SERVER_BRANCH=${y}",
"${agentEnvVar[tag]}=${x}",
"REUSE_CONTAINERS=true"
]
def label = "${tag}-${x}-${y}"
try{
steps.runScript(label: label, agentType: tag, env: env)
saveResult(x, y, 1)
} catch (e){
saveResult(x, y, 0)
error("${label} tests failed : ${e.toString()}\n")
} finally {
steps.wrappingup(label)
}
}
}
}
}
/**
Execute a test script.
runScript(tag: "Running Go integration test", agentType: "go", env: [ 'V1': 'value', 'V2':'value'])
*/
def runScript(Map params = [:]){
def label = params.containsKey('label') ? params.label : params?.agentType
def agentType = params.agentType
def env = params.env
log(level: 'INFO', text: "${label}")
deleteDir()
unstash "source"
dir("${BASE_DIR}"){
withEnv(env){
sh """#!/bin/bash
export TMPDIR="${WORKSPACE}"
./scripts/ci/${agentType}.sh
"""
}
}
}
def wrappingup(label){
dir("${BASE_DIR}"){
def stepName = label.replace(";","/")
.replace("--","_")
.replace(".","_")
sh("./scripts/docker-get-logs.sh '${stepName}'|| echo 0")
sh('make stop-env || echo 0')
archiveArtifacts(
allowEmptyArchive: true,
artifacts: 'docker-info/**,**/tests/results/data-*.json',
defaultExcludes: false)
junit(
allowEmptyResults: false,
keepLongStdio: true,
testResults: "**/tests/results/*-junit*.xml")
}
}