From 3d1a6b7d20696984bd2b5a70defc4950faa4a530 Mon Sep 17 00:00:00 2001 From: Victor Martinez Date: Wed, 7 Oct 2020 10:15:36 +0100 Subject: [PATCH 1/3] [BUILD][CI] fetch dependencies with retry --- Jenkinsfile | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Jenkinsfile b/Jenkinsfile index df75ad2ccd1..e2d7273ce60 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -269,6 +269,15 @@ def withBeatsEnv(Map args = [:], Closure body) { git config --global user.name "beatsmachine" fi''') } + // Add more stability when dependencies are not accessible temporarily + // See https://github.com/elastic/beats/issues/21609 + try { + retryWithSleep(retries: 2, seconds: 5, backoff: true){ + cmd(label: 'Fetch go dependencies', script: 'go get ./...') + } + }catch(err) { + log(level: 'WARN', text: "Go dependencies could not be fetched directly. Let's fallback in the build command itself.") + } try { body() } finally { From d5a6f4d03026539ca51db532b4d2158b0f713dea Mon Sep 17 00:00:00 2001 From: Victor Martinez Date: Wed, 7 Oct 2020 11:28:39 +0100 Subject: [PATCH 2/3] Run only for linux and avoid sh errors to keep the steps failures cleaner --- Jenkinsfile | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index e2d7273ce60..a437d30f250 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -268,15 +268,14 @@ def withBeatsEnv(Map args = [:], Closure body) { git config --global user.email "beatsmachine@users.noreply.github.com" git config --global user.name "beatsmachine" fi''') - } - // Add more stability when dependencies are not accessible temporarily - // See https://github.com/elastic/beats/issues/21609 - try { - retryWithSleep(retries: 2, seconds: 5, backoff: true){ - cmd(label: 'Fetch go dependencies', script: 'go get ./...') + + // Add more stability when dependencies are not accessible temporarily + // See https://github.com/elastic/beats/issues/21609 + // retry/try/catch approach reports errors, let's avoid it to keep the + // notifications cleaner. + if (sh(label: 'Fetch go dependencies', script: 'go get ./...', returnStatus: true) > 0) { + sh(label: 'Fetch go dependencies - retry', script: 'go get ./...', returnStatus: true) } - }catch(err) { - log(level: 'WARN', text: "Go dependencies could not be fetched directly. Let's fallback in the build command itself.") } try { body() From 2a7cd278f2be74e8c806bbd1aa27150b441deb4c Mon Sep 17 00:00:00 2001 From: Victor Martinez Date: Wed, 14 Oct 2020 14:49:20 +0100 Subject: [PATCH 3/3] use go mod download and support windows as suggested in the code review --- Jenkinsfile | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index fbd682811c5..b8949b1dad8 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -272,16 +272,15 @@ def withBeatsEnv(Map args = [:], Closure body) { git config --global user.email "beatsmachine@users.noreply.github.com" git config --global user.name "beatsmachine" fi''') - + } + try { // Add more stability when dependencies are not accessible temporarily // See https://github.com/elastic/beats/issues/21609 // retry/try/catch approach reports errors, let's avoid it to keep the // notifications cleaner. - if (sh(label: 'Fetch go dependencies', script: 'go get ./...', returnStatus: true) > 0) { - sh(label: 'Fetch go dependencies - retry', script: 'go get ./...', returnStatus: true) + if (cmd(label: 'Download modules to local cache', script: 'go mod download', returnStatus: true) > 0) { + cmd(label: 'Download modules to local cache - retry', script: 'go mod download', returnStatus: true) } - } - try { body() } finally { if (archive) {