From 2474f5b08096bf2734f5a2452a8c6e0031dd3384 Mon Sep 17 00:00:00 2001 From: Victor Martinez Date: Wed, 28 Oct 2020 15:26:01 +0000 Subject: [PATCH] [CI] archive only if failed steps (#22220) --- Jenkinsfile | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index d12848b28cc2..6fff22bfa09b 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -330,6 +330,8 @@ def withBeatsEnv(Map args = [:], Closure body) { git config --global user.name "beatsmachine" fi''') } + // Skip to upload the generated files by default. + def upload = false try { // Add more stability when dependencies are not accessible temporarily // See https://github.com/elastic/beats/issues/21609 @@ -339,9 +341,12 @@ def withBeatsEnv(Map args = [:], Closure body) { cmd(label: 'Download modules to local cache - retry', script: 'go mod download', returnStatus: true) } body() + } catch(err) { + // Upload the generated files ONLY if the step failed. This will avoid any overhead with Google Storage + upload = true } finally { if (archive) { - archiveTestOutput(testResults: testResults, artifacts: artifacts, id: args.id) + archiveTestOutput(testResults: testResults, artifacts: artifacts, id: args.id, upload: upload) } // Tear down the setup for the permamnent workers. catchError(buildResult: 'SUCCESS', stageResult: 'SUCCESS') { @@ -419,16 +424,20 @@ def archiveTestOutput(Map args = [:]) { script: 'rm -rf ve || true; find . -type d -name vendor -exec rm -r {} \\;') } else { log(level: 'INFO', text: 'Delete folders that are causing exceptions (See JENKINS-58421) is disabled for Windows.') } junitAndStore(allowEmptyResults: true, keepLongStdio: true, testResults: args.testResults, stashedTestReports: stashedTestReports, id: args.id) - tarAndUploadArtifacts(file: "test-build-artifacts-${args.id}.tgz", location: '.') + if (args.upload) { + tarAndUploadArtifacts(file: "test-build-artifacts-${args.id}.tgz", location: '.') + } } - catchError(buildResult: 'SUCCESS', message: 'Failed to archive the build test results', stageResult: 'SUCCESS') { - def folder = cmd(label: 'Find system-tests', returnStdout: true, script: 'python .ci/scripts/search_system_tests.py').trim() - log(level: 'INFO', text: "system-tests='${folder}'. If no empty then let's create a tarball") - if (folder.trim()) { - // TODO: nodeOS() should support ARM - def os_suffix = isArm() ? 'linux' : nodeOS() - def name = folder.replaceAll('/', '-').replaceAll('\\\\', '-').replaceAll('build', '').replaceAll('^-', '') + '-' + os_suffix - tarAndUploadArtifacts(file: "${name}.tgz", location: folder) + if (args.upload) { + catchError(buildResult: 'SUCCESS', message: 'Failed to archive the build test results', stageResult: 'SUCCESS') { + def folder = cmd(label: 'Find system-tests', returnStdout: true, script: 'python .ci/scripts/search_system_tests.py').trim() + log(level: 'INFO', text: "system-tests='${folder}'. If no empty then let's create a tarball") + if (folder.trim()) { + // TODO: nodeOS() should support ARM + def os_suffix = isArm() ? 'linux' : nodeOS() + def name = folder.replaceAll('/', '-').replaceAll('\\\\', '-').replaceAll('build', '').replaceAll('^-', '') + '-' + os_suffix + tarAndUploadArtifacts(file: "${name}.tgz", location: folder) + } } } }