Skip to content

Commit

Permalink
[CI]: retry with sleep (elastic#20065)
Browse files Browse the repository at this point in the history
  • Loading branch information
v1v authored and melchiormoulin committed Oct 14, 2020
1 parent 0eb10d6 commit 0750967
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 26 deletions.
18 changes: 18 additions & 0 deletions .ci/scripts/report-codecov.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env bash
set -exuo pipefail

CODECOV_URL=https://codecov.io/bash
if [ -e /usr/local/bin/bash_standard_lib.sh ] ; then
# shellcheck disable=SC1091
source /usr/local/bin/bash_standard_lib.sh
(retry 3 curl -sSLo codecov ${CODECOV_URL})
else
curl -sSLo codecov ${CODECOV_URL}
fi

for i in "$@" ; do
FILE="${i}/build/coverage/full.cov"
if [ -f "${FILE}" ]; then
bash codecov -f "${FILE}"
fi
done
37 changes: 11 additions & 26 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -947,7 +947,9 @@ def withBeatsEnv(Map args = [:], Closure body) {
if (archive) {
archiveTestOutput(testResults: '**/build/TEST*.xml', artifacts: '**/build/TEST*.out')
}
reportCoverage()
catchError(buildResult: 'SUCCESS', stageResult: 'UNSTABLE') {
sh(label: 'Report to Codecov', script: '.ci/scripts/report-codecov.sh auditbeat filebeat heartbeat journalbeat libbeat metricbeat packetbeat winlogbeat')
}
}
}
}
Expand Down Expand Up @@ -1021,12 +1023,12 @@ def withBeatsEnvWin(Map args = [:], Closure body) {
def installTools() {
def i = 2 // Number of retries
if(isUnix()) {
retry(i) { sh(label: "Install Go ${GO_VERSION}", script: ".ci/scripts/install-go.sh") }
retry(i) { sh(label: "Install docker-compose ${DOCKER_COMPOSE_VERSION}", script: ".ci/scripts/install-docker-compose.sh") }
retry(i) { sh(label: "Install Terraform ${TERRAFORM_VERSION}", script: ".ci/scripts/install-terraform.sh") }
retry(i) { sh(label: "Install Mage", script: "make mage") }
retryWithSleep(retries: i, seconds: 5, backoff: true){ sh(label: "Install Go ${GO_VERSION}", script: ".ci/scripts/install-go.sh") }
retryWithSleep(retries: i, seconds: 5, backoff: true){ sh(label: "Install docker-compose ${DOCKER_COMPOSE_VERSION}", script: ".ci/scripts/install-docker-compose.sh") }
retryWithSleep(retries: i, seconds: 5, backoff: true){ sh(label: "Install Terraform ${TERRAFORM_VERSION}", script: ".ci/scripts/install-terraform.sh") }
retryWithSleep(retries: i, seconds: 5, backoff: true){ sh(label: "Install Mage", script: "make mage") }
} else {
retry(i) { bat(label: "Install Go/Mage/Python ${GO_VERSION}", script: ".ci/scripts/install-tools.bat") }
retryWithSleep(retries: i, seconds: 5, backoff: true){ bat(label: "Install Go/Mage/Python ${GO_VERSION}", script: ".ci/scripts/install-tools.bat") }
}
}

Expand Down Expand Up @@ -1129,23 +1131,6 @@ def k8sTest(versions){
}
}

def reportCoverage(){
catchError(buildResult: 'SUCCESS', stageResult: 'UNSTABLE') {
retry(2){
sh(label: 'Report to Codecov', script: '''
curl -sSLo codecov https://codecov.io/bash
for i in auditbeat filebeat heartbeat libbeat metricbeat packetbeat winlogbeat journalbeat
do
FILE="${i}/build/coverage/full.cov"
if [ -f "${FILE}" ]; then
bash codecov -f "${FILE}"
fi
done
''')
}
}
}

/**
* isChanged treats the patterns as regular expressions. In order to check if
* any file in a directoy is modified use `^<path to dir>/.*`.
Expand Down Expand Up @@ -1251,7 +1236,7 @@ def startCloudTestEnv(String name, environments = []) {
try {
for (environment in environments) {
if (environment.cond || runAll) {
retry(2) {
retryWithSleep(retries: 2, seconds: 5, backoff: true){
terraformApply(environment.dir)
}
}
Expand All @@ -1273,7 +1258,7 @@ def terraformCleanup(String stashName, String directory) {
withCloudTestEnv() {
withBeatsEnv(archive: false, withModule: false) {
unstash("terraform-${stashName}")
retry(2) {
retryWithSleep(retries: 2, seconds: 5, backoff: true) {
sh(label: "Terraform Cleanup", script: ".ci/scripts/terraform-cleanup.sh ${directory}")
}
}
Expand All @@ -1286,7 +1271,7 @@ def loadConfigEnvVars(){
env.GO_VERSION = readFile(".go-version").trim()

withEnv(["HOME=${env.WORKSPACE}"]) {
retry(2) { sh(label: "Install Go ${env.GO_VERSION}", script: ".ci/scripts/install-go.sh") }
retryWithSleep(retries: 2, seconds: 5, backoff: true){ sh(label: "Install Go ${env.GO_VERSION}", script: ".ci/scripts/install-go.sh") }
}

// Libbeat is the core framework of Beats. It has no additional dependencies
Expand Down

0 comments on commit 0750967

Please sign in to comment.