From f902f48ac9a135a97e2869d6dfe6f2681ed36fd7 Mon Sep 17 00:00:00 2001 From: Googlom <36107508+Googlom@users.noreply.github.com> Date: Thu, 15 Aug 2024 16:19:59 +0500 Subject: [PATCH] Remove _master binary usage (#5002) * don't download _master binary * adjust tests --- src/com/sap/piper/PiperGoUtils.groovy | 3 +-- test/groovy/com/sap/piper/PiperGoUtilsTest.groovy | 12 ++++++------ 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/com/sap/piper/PiperGoUtils.groovy b/src/com/sap/piper/PiperGoUtils.groovy index d3ca507e87..0c6859e3b4 100644 --- a/src/com/sap/piper/PiperGoUtils.groovy +++ b/src/com/sap/piper/PiperGoUtils.groovy @@ -52,14 +52,13 @@ class PiperGoUtils implements Serializable { } } - def fallbackUrl = 'https://github.com/SAP/jenkins-library/releases/latest/download/piper_master' + def fallbackUrl = 'https://github.com/SAP/jenkins-library/releases/latest/download/piper' def piperBinUrl = (version == 'master') ? fallbackUrl : "https://github.com/SAP/jenkins-library/releases/download/${version}/piper" boolean downloaded = downloadGoBinary(piperBinUrl) if (!downloaded) { //Inform that no Piper binary is available for used library branch steps.echo ("Not able to download go binary of Piper for version ${version}") - //Fallback to master version & throw error in case this fails steps.retry(12) { if (!downloadGoBinary(fallbackUrl)) { steps.sleep(10) diff --git a/test/groovy/com/sap/piper/PiperGoUtilsTest.groovy b/test/groovy/com/sap/piper/PiperGoUtilsTest.groovy index 461c91dfac..94d49b55ed 100644 --- a/test/groovy/com/sap/piper/PiperGoUtilsTest.groovy +++ b/test/groovy/com/sap/piper/PiperGoUtilsTest.groovy @@ -63,11 +63,11 @@ class PiperGoUtilsTest extends BasePiperTest { }) shellCallRule.setReturnValue('[ -x ./piper ]', 1) - shellCallRule.setReturnValue('curl --insecure --silent --retry 5 --retry-max-time 240 --location --write-out \'%{http_code}\' --output piper \'https://github.com/SAP/jenkins-library/releases/latest/download/piper_master\'', '200') + shellCallRule.setReturnValue('curl --insecure --silent --retry 5 --retry-max-time 240 --location --write-out \'%{http_code}\' --output piper \'https://github.com/SAP/jenkins-library/releases/latest/download/piper\'', '200') piperGoUtils.unstashPiperBin() assertThat(shellCallRule.shell.size(), is(4)) - assertThat(shellCallRule.shell[1].toString(), is('curl --insecure --silent --retry 5 --retry-max-time 240 --location --write-out \'%{http_code}\' --output piper \'https://github.com/SAP/jenkins-library/releases/latest/download/piper_master\'')) + assertThat(shellCallRule.shell[1].toString(), is('curl --insecure --silent --retry 5 --retry-max-time 240 --location --write-out \'%{http_code}\' --output piper \'https://github.com/SAP/jenkins-library/releases/latest/download/piper\'')) assertThat(shellCallRule.shell[2].toString(), is('chmod +x piper')) assertThat(shellCallRule.shell[3].toString(), is('./piper version')) } @@ -102,7 +102,7 @@ class PiperGoUtilsTest extends BasePiperTest { shellCallRule.setReturnValue('[ -x ./piper ]', 1) shellCallRule.setReturnValue('./piper version', "1.2.3") shellCallRule.setReturnValue('curl --insecure --silent --retry 5 --retry-max-time 240 --location --write-out \'%{http_code}\' --output piper \'https://github.com/SAP/jenkins-library/releases/download/notAvailable/piper\'', '404') - shellCallRule.setReturnValue('curl --insecure --silent --retry 5 --retry-max-time 240 --location --write-out \'%{http_code}\' --output piper \'https://github.com/SAP/jenkins-library/releases/latest/download/piper_master\'', '200') + shellCallRule.setReturnValue('curl --insecure --silent --retry 5 --retry-max-time 240 --location --write-out \'%{http_code}\' --output piper \'https://github.com/SAP/jenkins-library/releases/latest/download/piper\'', '200') // this mocks utils.unstash - mimic stash not existing helper.registerAllowedMethod("unstash", [String.class], { stashFileName -> @@ -113,7 +113,7 @@ class PiperGoUtilsTest extends BasePiperTest { assertThat(shellCallRule.shell.size(), is(5)) assertThat(shellCallRule.shell[0].toString(), is('[ -x ./piper ]')) assertThat(shellCallRule.shell[1].toString(), is('curl --insecure --silent --retry 5 --retry-max-time 240 --location --write-out \'%{http_code}\' --output piper \'https://github.com/SAP/jenkins-library/releases/download/notAvailable/piper\'')) - assertThat(shellCallRule.shell[2].toString(), is('curl --insecure --silent --retry 5 --retry-max-time 240 --location --write-out \'%{http_code}\' --output piper \'https://github.com/SAP/jenkins-library/releases/latest/download/piper_master\'')) + assertThat(shellCallRule.shell[2].toString(), is('curl --insecure --silent --retry 5 --retry-max-time 240 --location --write-out \'%{http_code}\' --output piper \'https://github.com/SAP/jenkins-library/releases/latest/download/piper\'')) assertThat(shellCallRule.shell[3].toString(), is('chmod +x piper')) assertThat(shellCallRule.shell[4].toString(), is ('./piper version')) } @@ -125,7 +125,7 @@ class PiperGoUtilsTest extends BasePiperTest { shellCallRule.setReturnValue('[ -x ./piper ]', 1) shellCallRule.setReturnValue('curl --insecure --silent --retry 5 --retry-max-time 240 --location --write-out \'%{http_code}\' --output piper \'https://github.com/SAP/jenkins-library/releases/download/notAvailable/piper\'', '404') - shellCallRule.setReturnValue('curl --insecure --silent --retry 5 --retry-max-time 240 --location --write-out \'%{http_code}\' --output piper \'https://github.com/SAP/jenkins-library/releases/latest/download/piper_master\'', '500') + shellCallRule.setReturnValue('curl --insecure --silent --retry 5 --retry-max-time 240 --location --write-out \'%{http_code}\' --output piper \'https://github.com/SAP/jenkins-library/releases/latest/download/piper\'', '500') helper.registerAllowedMethod("unstash", [String.class], { stashFileName -> return [] @@ -142,7 +142,7 @@ class PiperGoUtilsTest extends BasePiperTest { shellCallRule.setReturnValue('[ -x ./piper ]', 1) shellCallRule.setReturnValue('curl --insecure --silent --retry 5 --retry-max-time 240 --location --write-out \'%{http_code}\' --output piper \'https://github.com/SAP/jenkins-library/releases/download/notAvailable/piper\'', '404') - shellCallRule.setReturnValue('curl --insecure --silent --retry 5 --retry-max-time 240 --location --write-out \'%{http_code}\' --output piper \'https://github.com/SAP/jenkins-library/releases/latest/download/piper_master\'', '500') + shellCallRule.setReturnValue('curl --insecure --silent --retry 5 --retry-max-time 240 --location --write-out \'%{http_code}\' --output piper \'https://github.com/SAP/jenkins-library/releases/latest/download/piper\'', '500') helper.registerAllowedMethod("unstash", [String.class], { stashFileName -> return []