From 5bfc5aa44bf08c8528e7aa95013344e2ec165438 Mon Sep 17 00:00:00 2001 From: Victor Martinez Date: Tue, 3 Nov 2020 10:44:15 +0000 Subject: [PATCH] [CI] cleanup terraform when errors (#22356) --- Jenkinsfile | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index f0f1b3e5e99..606a6939250 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -458,11 +458,16 @@ def startCloudTestEnv(Map args = [:]) { withCloudTestEnv() { withBeatsEnv(archive: false, withModule: false) { try { - for (folder in dirs) { + dirs?.each { folder -> retryWithSleep(retries: 2, seconds: 5, backoff: true){ terraformApply(folder) } } + } catch(err) { + dirs?.each { folder -> + // If it failed then cleanup without failing the build + sh(label: 'Terraform Cleanup', script: ".ci/scripts/terraform-cleanup.sh ${folder}", returnStatus: true) + } } finally { // Archive terraform states in case manual cleanup is needed. archiveArtifacts(allowEmptyArchive: true, artifacts: '**/terraform.tfstate')