Skip to content

Commit

Permalink
[CI] refactor runbld post build action (#21256) (#21342)
Browse files Browse the repository at this point in the history
  • Loading branch information
v1v authored Sep 29, 2020
1 parent 1c94c6d commit 04de78d
Showing 1 changed file with 4 additions and 47 deletions.
51 changes: 4 additions & 47 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ pipeline {
agent { label 'ubuntu-18 && immutable' }
environment {
AWS_ACCOUNT_SECRET = 'secret/observability-team/ci/elastic-observability-aws-account-auth'
BASE_DIR = 'src/github.com/elastic/beats'
REPO = 'beats'
BASE_DIR = "src/github.com/elastic/${env.REPO}"
DOCKERELASTIC_SECRET = 'secret/observability-team/ci/docker-registry/prod'
DOCKER_COMPOSE_VERSION = "1.21.0"
DOCKER_REGISTRY = 'docker.elastic.co'
Expand Down Expand Up @@ -121,7 +122,7 @@ pipeline {
}
post {
always {
runbld()
runbld(stashedTestReports: stashedTestReports, project: env.REPO)
}
cleanup {
notifyBuildResult(prComment: true)
Expand Down Expand Up @@ -347,7 +348,7 @@ def archiveTestOutput(Map args = [:]) {
}
cmd(label: 'Prepare test output', script: 'python .ci/scripts/pre_archive_test.py')
dir('build') {
junitAndStore(allowEmptyResults: true, keepLongStdio: true, testResults: args.testResults, id: args.id)
junitAndStore(allowEmptyResults: true, keepLongStdio: true, testResults: args.testResults, stashedTestReports: stashedTestReports, id: args.id)
archiveArtifacts(allowEmptyArchive: true, artifacts: args.artifacts)
}
catchError(buildResult: 'SUCCESS', message: 'Failed to archive the build test results', stageResult: 'SUCCESS') {
Expand All @@ -361,50 +362,6 @@ def archiveTestOutput(Map args = [:]) {
}
}

/**
* This method wraps the junit built-in step to archive the test reports that gonna be populated later on
* with the runbld post build step.
*/
def junitAndStore(Map args = [:]) {
junit(args)
// args.id could be null in some cases, so let's use the currentmilliseconds
def stageName = args.id ? args.id?.replaceAll("[\\W]|_",'-') : "uncategorized-${new java.util.Date().getTime()}"
stash(includes: args.testResults, allowEmpty: true, name: stageName, useDefaultExcludes: true)
stashedTestReports[stageName] = stageName
}

/**
* This method populates the test output using the runbld approach. For such it requires the
* global variable stashedTestReports.
* TODO: should be moved to the shared library
*/
def runbld() {
catchError(buildResult: 'SUCCESS', message: 'runbld post build action failed.') {
if (stashedTestReports) {
def jobName = isPR() ? 'elastic+beats+pull-request' : 'elastic+beats'
deleteDir()
unstashV2(name: 'source', bucket: "${JOB_GCS_BUCKET}", credentialsId: "${JOB_GCS_CREDENTIALS}")
dir("${env.BASE_DIR}") {
// Unstash the test reports
stashedTestReports.each { k, v ->
dir(k) {
unstash(v)
}
}
}
sh(label: 'Process JUnit reports with runbld',
script: """\
## for debugging purposes
find . -name "TEST-*.xml"
cat >./runbld-script <<EOF
echo "Processing JUnit reports with runbld..."
EOF
/usr/local/bin/runbld ./runbld-script --job-name ${jobName}
""".stripIndent()) // stripIdent() requires '''/
}
}
}

/**
* This method executes a closure with credentials for cloud test
* environments.
Expand Down

0 comments on commit 04de78d

Please sign in to comment.