diff --git a/jenkins-scripts/dsl/_configs_/OSRFLinuxBase.groovy b/jenkins-scripts/dsl/_configs_/OSRFLinuxBase.groovy index bdce34f57..884ace6e1 100644 --- a/jenkins-scripts/dsl/_configs_/OSRFLinuxBase.groovy +++ b/jenkins-scripts/dsl/_configs_/OSRFLinuxBase.groovy @@ -19,6 +19,47 @@ class OSRFLinuxBase { label "docker" + parameters { + booleanParam('WORKSPACE_CLEANUP', true, + 'Disable to keep build artifacts in Jenkins for debugging') + } + + // No DSL code to support new changes in postBuildScripts, injection DSL + // code directly. https://issues.jenkins.io/browse/JENKINS-66189 + configure { project -> + project / 'publishers' / 'org.jenkinsci.plugins.postbuildscript.PostBuildScript' / 'config' { + scriptFiles() + groovyScripts() + buildSteps { + 'org.jenkinsci.plugins.postbuildscript.model.PostBuildStep' { + results { + string 'SUCCESS' + string 'NOT_BUILT' + string 'ABORTED' + string 'FAILURE' + string 'UNSTABLE' + } + role('SLAVE') + buildSteps { + 'hudson.tasks.Shell' { + command("""\ + #!/bin/bash -xe + # Clean up build directory no matter what have happened to the + # build except to test_results + if \${WORKSPACE_CLEANUP} && [ -d \${WORKSPACE}/build ]; then + sudo find \${WORKSPACE}/build -maxdepth 1 -mindepth 1 ! -name test_results -exec rm -rv {} + + echo "Disable WORKSPACE_CLEANUP parameter to avoid cleanup" > \${WORKSPACE}/build_dir_was_cleaned_up + fi + """.stripIndent()) + configuredLocalRules() + } + } + } + } + markBuildUnstable(false) + } + } + publishers { archiveArtifacts { pattern('Dockerfile') @@ -27,8 +68,8 @@ class OSRFLinuxBase // these files (i.e: testing job). Do not fail if they are not // present allowEmpty(true) + } } - } } } }