This repository has been archived by the owner on Sep 17, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 42
/
Jenkinsfile
538 lines (500 loc) · 23.9 KB
/
Jenkinsfile
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
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
#!/usr/bin/env groovy
@Library('apm@current') _
pipeline {
agent { label 'ubuntu-20.04 && immutable && docker' }
environment {
REPO = 'e2e-testing'
BASE_DIR = "src/github.com/elastic/${env.REPO}"
ELASTIC_APM_ACTIVE="true"
ELASTIC_APM_ENVIRONMENT="ci"
ELASTIC_APM_LOG_FILE="stderr"
ELASTIC_APM_LOG_LEVEL="debug"
NIGHTLY_TAG="@nightly"
NOTIFY_TO = credentials('notify-to')
JOB_GCS_BUCKET = credentials('gcs-bucket')
JOB_GIT_CREDENTIALS = "2a9602aa-ab9f-4e52-baf3-b71ca88469c7-UserAndToken"
DOCKER_ELASTIC_SECRET = 'secret/observability-team/ci/docker-registry/prod'
DOCKER_REGISTRY = 'docker.elastic.co'
ELASTIC_CLOUD_SECRET = 'secret/observability-team/ci/elastic-cloud/observability-team-user'
GCP_PROVISIONER_SECRET = 'secret/observability-team/ci/service-account/jenkins-gce-provisioner'
AWS_PROVISIONER_SECRET = 'secret/observability-team/ci/elastic-observability-aws-account-auth'
TEST_MATRIX_FILE = "${params.testMatrixFile}"
RUN_ID = UUID.randomUUID().toString()
}
options {
timeout(time: 1, unit: 'HOURS')
buildDiscarder(logRotator(numToKeepStr: '20', artifactNumToKeepStr: '20', daysToKeepStr: '30'))
timestamps()
ansiColor('xterm')
disableResume()
durabilityHint('PERFORMANCE_OPTIMIZED')
rateLimitBuilds(throttle: [count: 60, durationName: 'hour', userBoost: true])
quietPeriod(10)
}
triggers {
issueCommentTrigger("${obltGitHubComments()}")
}
parameters {
booleanParam(name: 'Run_As_Master_Branch', defaultValue: false, description: 'Allow to run any steps on a PR, some steps normally only run on master branch.')
booleanParam(name: "SKIP_SCENARIOS", defaultValue: true, description: "If it's needed to skip those scenarios marked as @skip. Default true")
booleanParam(name: "NIGHTLY_SCENARIOS", defaultValue: false, description: "If it's needed to include the scenarios marked as @nightly in the test execution. Default false")
string(name: 'runTestsSuites', defaultValue: '', description: 'A comma-separated list of test suites to run (default: empty to run all test suites)')
string(name: 'testMatrixFile', defaultValue: '.ci/.e2e-tests.yaml', description: 'The file with the test suite and scenarios to be tested.')
booleanParam(name: "forceSkipGitChecks", defaultValue: false, description: "If it's needed to check for Git changes to filter by modified sources")
booleanParam(name: "forceSkipPresubmit", defaultValue: false, description: "If it's needed to execute the pre-submit tests: unit and precommit.")
booleanParam(name: "notifyOnGreenBuilds", defaultValue: false, description: "If it's needed to notify to Slack with green builds.")
string(name: 'SLACK_CHANNEL', defaultValue: 'observablt-bots', description: 'The Slack channel(s) where errors will be posted. For multiple channels, use a comma-separated list of channels')
string(name: 'ELASTIC_AGENT_DOWNLOAD_URL', defaultValue: '', description: 'If present, it will override the download URL for the Elastic agent artifact. (I.e. https://snapshots.elastic.co/8.0.0-59098054/downloads/beats/elastic-agent/elastic-agent-8.0.0-SNAPSHOT-linux-x86_64.tar.gz')
string(name: 'BEAT_VERSION', defaultValue: '8.1.0-befff95a-SNAPSHOT', description: 'SemVer version of the Beat to be used for the tests. You can use here the tag of your PR to test your changes')
string(name: 'ELASTIC_AGENT_STALE_VERSION', defaultValue: '7.15-SNAPSHOT', description: 'SemVer version of the stale stand-alone elastic-agent to be used for Fleet upgrade tests.')
choice(name: 'LOG_LEVEL', choices: ['DEBUG', 'TRACE', 'INFO'], description: 'Log level to be used')
choice(name: 'TIMEOUT_FACTOR', choices: ['5', '3', '7', '11'], description: 'Max number of minutes for timeout backoff strategies')
string(name: 'KIBANA_VERSION', defaultValue: '', description: 'Docker tag of the kibana to be used for the tests. It will refer to an image related to a Kibana PR, under the Observability-CI namespace')
string(name: 'STACK_VERSION', defaultValue: '8.1.0-befff95a-SNAPSHOT', description: 'SemVer version of the stack to be used for the tests.')
string(name: 'HELM_CHART_VERSION', defaultValue: '7.11.2', description: 'SemVer version of Helm chart to be used.')
string(name: 'HELM_VERSION', defaultValue: '3.5.2', description: 'SemVer version of Helm to be used.')
string(name: 'KIND_VERSION', defaultValue: '0.10.0', description: 'SemVer version of Kind to be used.')
string(name: 'KUBERNETES_VERSION', defaultValue: '1.18.2', description: 'SemVer version of Kubernetes to be used.')
string(name: 'GITHUB_CHECK_NAME', defaultValue: '', description: 'Name of the GitHub check to be updated. Only if this build is triggered from another parent stream.')
string(name: 'GITHUB_CHECK_REPO', defaultValue: '', description: 'Name of the GitHub repo to be updated. Only if this build is triggered from another parent stream.')
string(name: 'GITHUB_CHECK_SHA1', defaultValue: '', description: 'Git SHA for the Beats upstream project (branch or PR)')
}
stages {
stage('Initializing'){
options { skipDefaultCheckout() }
environment {
HOME = "${env.WORKSPACE}"
PATH = "${env.PATH}:${env.WORKSPACE}/bin:${env.WORKSPACE}/${env.BASE_DIR}/.ci/scripts"
GO111MODULE = 'on'
SKIP_SCENARIOS = "${params.SKIP_SCENARIOS}"
NIGHTLY_SCENARIOS = "${params.NIGHTLY_SCENARIOS}"
SLACK_CHANNEL = "${params.SLACK_CHANNEL.trim()}"
ELASTIC_AGENT_DOWNLOAD_URL = "${params.ELASTIC_AGENT_DOWNLOAD_URL.trim()}"
BEAT_VERSION = "${params.BEAT_VERSION.trim()}"
KIBANA_VERSION = "${params.KIBANA_VERSION.trim()}"
STACK_VERSION = "${params.STACK_VERSION.trim()}"
FORCE_SKIP_GIT_CHECKS = "${params.forceSkipGitChecks}"
FORCE_SKIP_PRESUBMIT = "${params.forceSkipPresubmit}"
HELM_CHART_VERSION = "${params.HELM_CHART_VERSION.trim()}"
HELM_VERSION = "${params.HELM_VERSION.trim()}"
KIND_VERSION = "${params.KIND_VERSION.trim()}"
KUBERNETES_VERSION = "${params.KUBERNETES_VERSION.trim()}"
LOG_LEVEL = "${params.LOG_LEVEL.trim()}"
TIMEOUT_FACTOR = "${params.TIMEOUT_FACTOR.trim()}"
}
stages {
stage('Checkout') {
steps {
pipelineManager([ cancelPreviousRunningBuilds: [ when: 'PR' ] ])
deleteDir()
gitCheckout(basedir: BASE_DIR, githubNotifyFirstTimeContributor: true)
githubCheckNotify('PENDING') // we want to notify the upstream about the e2e the soonest
stash allowEmpty: true, name: 'source', useDefaultExcludes: false
setEnvVar("GO_VERSION", readFile("${env.WORKSPACE}/${env.BASE_DIR}/.go-version").trim())
checkSkipTests()
}
}
stage('Pre-Submit') {
when {
beforeAgent true
expression { return env.FORCE_SKIP_PRESUBMIT == "false" }
}
parallel {
stage('Sanity checks') {
agent { label 'ubuntu-20.04 && immutable && docker' }
environment {
PATH = "${env.WORKSPACE}/${env.BASE_DIR}/bin:${env.PATH}"
GO111MODULE = 'auto'
}
options { skipDefaultCheckout() }
steps {
withGithubNotify(context: 'Sanity checks', tab: 'tests') {
deleteDir()
unstash 'source'
withGoEnv(version: "${GO_VERSION}"){
dir(BASE_DIR){
retryWithSleep(retries: 2, seconds: 5, backoff: true){ sh script: '.ci/scripts/install-dependencies.sh', label: 'Install dependencies' }
preCommit(commit: "${GIT_BASE_COMMIT}", junit: true)
}
}
}
}
}
stage('Unit Tests') {
options { skipDefaultCheckout() }
when {
beforeAgent true
anyOf {
expression { return env.FORCE_SKIP_GIT_CHECKS == "true" }
expression { return env.SKIP_TESTS == "false" }
}
}
steps {
withGithubNotify(context: 'Tests', tab: 'tests') {
deleteDir()
unstash 'source'
withGoEnv(version: "${GO_VERSION}"){
dir(BASE_DIR){
sh script: '.ci/scripts/build-test.sh', label: 'Build and test'
}
}
}
}
post {
always {
junit(allowEmptyResults: true, keepLongStdio: true, testResults: "${BASE_DIR}/outputs/TEST-unit-*.xml")
archiveArtifacts allowEmptyArchive: true, artifacts: "${BASE_DIR}/outputs/TEST-unit-*.xml"
}
}
}
}
}
stage('Build Docs') {
options { skipDefaultCheckout() }
when {
beforeAgent true
anyOf {
expression { return env.FORCE_SKIP_GIT_CHECKS == "true" }
expression { return env.SKIP_TESTS == "false" }
}
}
steps {
deleteDir()
unstash 'source'
dockerLogin(secret: "${DOCKER_ELASTIC_SECRET}", registry: "${DOCKER_REGISTRY}")
dir("${BASE_DIR}/e2e") {
sh(label: 'Build docs', script: 'make build-docs')
}
}
post {
always {
dir("${BASE_DIR}") {
archiveArtifacts allowEmptyArchive: true, artifacts: "e2e/docs/**"
}
}
}
}
stage('Deploy Test Infra') {
failFast true
options { skipDefaultCheckout() }
environment {
GO111MODULE = 'on'
PATH = "${env.HOME}/bin:${env.WORKSPACE}/${env.BASE_DIR}/bin:${HOME}/go/bin:${env.PATH}"
}
when {
beforeAgent true
anyOf {
expression { return env.FORCE_SKIP_GIT_CHECKS == "true" }
expression { return env.SKIP_TESTS == "false" }
}
}
steps {
withGithubNotify(context: 'Deploy Stack', tab: 'tests') {
deleteDir()
unstash 'source'
dir("${BASE_DIR}") {
script {
def stackWorkspace = "${env.WORKSPACE}/${env.BASE_DIR}"
// Deploy the test infrastructure
sh "ssh-keygen -b 4096 -t rsa -f ${stackWorkspace}/e2essh -q -N \"\" "
def stackMachine = getMachineInfo(stackWorkspace, 'stack')
ansible(stackWorkspace,
env.RUN_ID.split('-')[0],
"-t provision-stack --extra-vars=\"nodeLabel=stack nodeImage=${stackMachine.image} nodeInstanceType=${stackMachine.instance_type}\"")
// Must be gathered after deployment as the public IP is known at that time
def stackRunner = getNodeIp(stackWorkspace, 'stack')
ansible(stackWorkspace,
env.RUN_ID.split('-')[0],
"-i \"${stackRunner.ip},\" -t setup-stack --extra-vars=\"nodeLabel=stack nodeImage=${stackMachine.image} nodeInstanceType=${stackMachine.instance_type}\"")
// Update stash with latest changes from the stack deployment
stash allowEmpty: true, name: 'sourceEnvModified', useDefaultExcludes: false
}
}
}
}
}
stage('End-To-End Tests') {
failFast true
options { skipDefaultCheckout() }
environment {
GO111MODULE = 'on'
PATH = "${env.HOME}/bin:${env.WORKSPACE}/${env.BASE_DIR}/bin:${HOME}/go/bin:${env.PATH}"
}
when {
beforeAgent true
anyOf {
expression { return env.FORCE_SKIP_GIT_CHECKS == "true" }
expression { return env.SKIP_TESTS == "false" }
}
}
steps {
withGithubNotify(context: 'E2E Tests', tab: 'tests') {
script {
def suitesParam = params.runTestsSuites
def existingSuites = readYaml(file: "${env.WORKSPACE}/${env.BASE_DIR}/${TEST_MATRIX_FILE}")
def parallelTasks = [:]
if (suitesParam == "") {
log(level: 'DEBUG', text: "Iterate through existing test suites")
existingSuites['SUITES'].each { item ->
checkTestSuite(parallelTasks, item)
}
} else {
log(level: 'DEBUG', text: "Iterate through the comma-separated test suites (${suitesParam}), comparing with the existing test suites")
suitesParam.split(',').each { suiteParam ->
existingSuites['SUITES'].findAll { suiteParam.trim() == it.suite }.each { item ->
checkTestSuite(parallelTasks, item)
}
}
}
parallel(parallelTasks)
}
}
}
post {
cleanup {
// Once all tests are complete we need to teardown the single instance with the deployed stack
script {
def stackWorkspace = "${env.WORKSPACE}/${env.BASE_DIR}"
def stackMachine = getMachineInfo(stackWorkspace, 'stack')
ansible(stackWorkspace,
env.RUN_ID.split('-')[0],
"-t destroy --extra-vars=\"nodeLabel=stack nodeImage=${stackMachine.image} nodeInstanceType=${stackMachine.instance_type}\"")
}
}
}
}
stage('Release') {
options { skipDefaultCheckout() }
when { tag "v*" }
steps {
deleteDir()
unstash 'source'
dir("${BASE_DIR}") {
setEnvVar("GITHUB_TOKEN", getGithubToken())
retryWithSleep(retries: 2, seconds: 5, backoff: true) {
sh(label: 'Release binaries with gorelease', script: 'curl -sL https://git.io/goreleaser | bash -s -- --rm-dist', returnStatus: true)
}
}
}
post {
always {
archiveArtifacts allowEmptyArchive: true, artifacts: "${BASE_DIR}/cli/dist/**"
}
}
}
}
}
}
post {
cleanup {
doNotifyBuildResult(params.notifyOnGreenBuilds)
}
}
}
// this function evaluates if the test stage of the build must be executed
def checkSkipTests() {
dir("${BASE_DIR}"){
// only docs means no tests are run
if (isGitRegionMatch(patterns: [ '.*\\.md' ], shouldMatchAll: true)) {
setEnvVar("SKIP_TESTS", true)
return
}
// patterns for all places that should trigger a full build
def regexps = [ "^e2e/_suites/fleet/.*", "^e2e/_suites/helm/.*", "^e2e/_suites/kubernetes-autodiscover/.*", "^.ci/.*", "^cli/.*", "^e2e/.*\\.go", "^internal/.*\\.go" ]
setEnvVar("SKIP_TESTS", !isGitRegionMatch(patterns: regexps, shouldMatchAll: false))
}
}
def sshexec(workspace, connection, cmd){
sh "ssh -tt -o TCPKeepAlive=yes -o ServerAliveInterval=60 -o ServerAliveCountMax=10 -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i ${workspace}/e2essh ${connection.user}@${connection.ip} -- '${cmd}'"
}
def scpr(workspace, connection, remote_src, local_dst){
sh "scp -r -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i ${workspace}/e2essh ${connection.user}@${connection.ip}:${remote_src} ${local_dst}"
}
/*
* Runs python in venv
*/
def pyrun(command){
def awsProps = getVaultSecret(secret: "${AWS_PROVISIONER_SECRET}")
def awsAuthObj = awsProps?.data
withEnv([
"ANSIBLE_HOST_KEY_CHECKING=False",
]){
withVaultToken(){
withEnvMask(vars: [
[var: "AWS_ACCESS_KEY_ID", password: awsAuthObj.access_key],
[var: "AWS_SECRET_ACCESS_KEY", password: awsAuthObj.secret_key]
]) {
sh(script: """#!/bin/bash
set -eux
if ! test -d ${env.WORKSPACE}/.venv; then
python3 -m venv ${env.WORKSPACE}/.venv
${env.WORKSPACE}/.venv/bin/pip3 -q install wheel
${env.WORKSPACE}/.venv/bin/pip3 -q install ansible requests boto3 boto
${env.WORKSPACE}/.venv/bin/ansible-galaxy install -r .ci/ansible/requirements.yml
fi
${env.WORKSPACE}/.venv/bin/${command}
""",
label: "Executing ${command.split(' ')[0]}"
)
}
}
}
}
def getNodeIp(workspace, platform){
def runners = readYaml(file: "${workspace}/${platform}-sshhosts")
def runnerUser = runners[0].split('@')[0]
def runnerIP = runners[0].split('@')[1]
return [user: runnerUser, ip: runnerIP]
}
def getMachineInfo(workspace, platform){
def machineYaml = readYaml(file: "${workspace}/${TEST_MATRIX_FILE}")
def machines = machineYaml['PLATFORMS']
return machines.get(platform)
}
def ansible(workspace, run_id, args){
pyrun("ansible-playbook --private-key=\"${workspace}/e2essh\" --extra-vars=\"workspace=${workspace}/ runId=${run_id} sshPublicKey=${workspace}/e2essh.pub\" --ssh-common-args='-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null' ${workspace}/.ci/ansible/playbook.yml ${args}")
}
def checkTestSuite(Map parallelTasks = [:], Map item = [:]) {
def suite = item.suite
def platforms = item.platforms
item.scenarios.each { scenario ->
def name = scenario.name
def platformsValue = platforms
def scenarioPlatforms = scenario.platforms
if (scenarioPlatforms?.size() > 0) {
// scenario platforms take precedence over suite platforms, overriding them
platformsValue = scenarioPlatforms
}
def pullRequestFilter = scenario.containsKey('pullRequestFilter') ? scenario.pullRequestFilter : ''
def tags = scenario.tags
platformsValue.each { platform ->
log(level: 'INFO', text: "Adding ${platform}:${suite}:${tags} test suite to the build execution")
machineInfo = getMachineInfo("${env.WORKSPACE}/${env.BASE_DIR}", platform)
parallelTasks["${platform}_${tags}"] = generateFunctionalTestStep(name: "${name}",
platform: platform,
suite: "${suite}",
tags: "${tags}",
pullRequestFilter: "${pullRequestFilter}",
machine: machineInfo)
}
}
}
/*
* Sends out notification of the build result to Slack
*/
def doNotifyBuildResult(boolean slackNotify) {
githubCheckNotify(currentBuild.currentResult == 'SUCCESS' ? 'SUCCESS' : 'FAILURE')
def testsSuites = "${params.runTestsSuites}"
if (testsSuites?.trim() == "") {
testsSuites = "All suites"
}
def channels = "${env.SLACK_CHANNEL}"
if (channels?.trim() == "") {
channels = "observablt-bots"
}
def header = "*Test Suite*: " + testsSuites
notifyBuildResult(analyzeFlakey: true,
jobName: getFlakyJobName(withBranch: "${env.JOB_BASE_NAME}"),
prComment: true,
slackHeader: header,
slackChannel: "${channels}",
slackComment: true,
slackNotify: slackNotify)
}
/**
Notify the GitHub check of the parent stream
**/
def githubCheckNotify(String status) {
if (params.GITHUB_CHECK_NAME?.trim() && params.GITHUB_CHECK_REPO?.trim() && params.GITHUB_CHECK_SHA1?.trim()) {
githubNotify context: "${params.GITHUB_CHECK_NAME}",
description: "${params.GITHUB_CHECK_NAME} ${status.toLowerCase()}",
status: "${status}",
targetUrl: "${env.RUN_DISPLAY_URL}",
sha: params.GITHUB_CHECK_SHA1, account: 'elastic', repo: params.GITHUB_CHECK_REPO, credentialsId: env.JOB_GIT_CREDENTIALS
}
}
def generateFunctionalTestStep(Map args = [:]){
def name = args.get('name')
def name_normalize = name.replace(' ', '_')
def platform = args.get('platform')
def suite = args.get('suite')
def tags = args.get('tags')
def pullRequestFilter = args.get('pullRequestFilter')?.trim() ? args.get('pullRequestFilter') : ''
def machine = args.get('machine')
// We will decide whether to include the nightly tests in the execution at CI time, only.
// On the other hand, the developers can use the TAGS environment variable locally.
// Finally, we positively know that tags are not empty, so we can use AND operator.
def excludeNightlyTag = " && ~${NIGHTLY_TAG}"
if ("${NIGHTLY_SCENARIOS}" == "true") {
excludeNightlyTag = ""
}
tags += excludeNightlyTag
// TODO: Is this still relevant?
if (isPR() || isUpstreamTrigger(filter: 'PR-')) {
// when the "Run_As_Master_Branch" param is disabled, we will honour the PR filters, which
// basically exclude some less frequent platforms or operative systems. If the user enabled
// this param, the pipeline will remove the filters from the test runner.
if (!params.Run_As_Master_Branch) {
tags += pullRequestFilter
}
}
def goArch = "amd64"
if (platform.contains("arm64")) {
goArch = "arm64"
}
// Skip scenarios per platform
tags += " && ~@skip:${goArch}"
// Setup environment for platform
def envContext = []
// envContext.add("PROVIDER=${platformProvider}")
envContext.add("SUITE=${suite}")
envContext.add("ELASTIC_APM_GLOBAL_LABELS=branch_name=${BRANCH_NAME},build_pr=${isPR()},build_id=${env.BUILD_ID},go_arch=${goArch},beat_version=${env.BEAT_VERSION},stack_version=${env.STACK_VERSION}")
def stackRunner = getNodeIp("${env.WORKSPACE}/${env.BASE_DIR}", 'stack')
def runId = UUID.randomUUID().toString().split('-')[0]
return {
withNode(labels: 'ubuntu-20.04', forceWorkspace: true, forceWorker: true){
try {
deleteDir()
unstash 'sourceEnvModified'
withEnv(envContext) {
// This step will help to send the APM traces to the
// APM service defined by the Otel Jenkins plugin.
// TODO: This will need to be integrated into the provisioned VMs
withOtelEnv() {
// Start node, capture ip address
ansible("${env.WORKSPACE}",
runId,
"-t start-node --extra-vars=\"stackRunner=${stackRunner.ip} nodeLabel=${platform} nodeImage=${machine.image} nodeInstanceType=${machine.instance_type}\"")
def testRunner = getNodeIp("${env.WORKSPACE}", platform)
// Configure node for testing
ansible("${env.WORKSPACE}",
runId,
"-i \"${testRunner.ip},\" -t setup-node --extra-vars=\"stackRunner=${stackRunner.ip} nodeLabel=${platform} nodeImage=${machine.image} nodeInstanceType=${machine.instance_type}\"")
sshexec("${env.WORKSPACE}",
testRunner,
"""sudo bash /home/${testRunner.user}/e2e-testing/.ci/scripts/functional-test.sh "${tags}" """)
}
}
} finally {
def testRunner = getNodeIp("${env.WORKSPACE}", platform)
sh "mkdir -p outputs/${testRunner.ip} || true"
sshexec("${env.WORKSPACE}",
testRunner,
"""sudo chown ${testRunner.user}:${testRunner.user} -R /home/${testRunner.user}/e2e-testing/outputs """)
scpr("${env.WORKSPACE}",
testRunner,
"e2e-testing/outputs/TEST-*${runId}*.xml",
"outputs/${testRunner.ip}/.")
sh "ls -l outputs/${testRunner.ip}"
ansible("${env.WORKSPACE}",
runId,
"-t destroy --extra-vars=\"nodeLabel=${platform} nodeImage=${machine.image} nodeInstanceType=${machine.instance_type}\"")
junit allowEmptyResults: true,
keepLongStdio: true,
testResults: "outputs/${testRunner.ip}/TEST-*${runId}*.xml"
archiveArtifacts allowEmptyArchive: true,
artifacts: "outputs/${testRunner.ip}/TEST-*${runId}*.xml"
}
}
}
}