Skip to content

Commit

Permalink
A retry has been added to the curl that downloads the piper (#4315)
Browse files Browse the repository at this point in the history
Co-authored-by: Oliver Feldmann <[email protected]>
  • Loading branch information
kamil7108 and o-liver authored Apr 24, 2023
1 parent 01cfb07 commit 54d543a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/com/sap/piper/PiperGoUtils.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class PiperGoUtils implements Serializable {
private boolean downloadGoBinary(url) {

try {
def httpStatus = steps.sh(returnStdout: true, script: "curl --insecure --silent --location --write-out '%{http_code}' --output ${piperExecutable} '${url}'")
def httpStatus = steps.sh(returnStdout: true, script: "curl --insecure --silent --retry 5 --retry-max-time 240 --location --write-out '%{http_code}' --output ${piperExecutable} '${url}'")

if (httpStatus == '200') {
steps.sh(script: "chmod +x ${piperExecutable}")
Expand Down
24 changes: 12 additions & 12 deletions test/groovy/com/sap/piper/PiperGoUtilsTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ class PiperGoUtilsTest extends BasePiperTest {
})

shellCallRule.setReturnValue('[ -x ./piper ]', 1)
shellCallRule.setReturnValue('curl --insecure --silent --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_master\'', '200')

piperGoUtils.unstashPiperBin()
assertThat(shellCallRule.shell.size(), is(4))
assertThat(shellCallRule.shell[1].toString(), is('curl --insecure --silent --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_master\''))
assertThat(shellCallRule.shell[2].toString(), is('chmod +x piper'))
assertThat(shellCallRule.shell[3].toString(), is('./piper version'))
}
Expand All @@ -84,11 +84,11 @@ class PiperGoUtilsTest extends BasePiperTest {
})

shellCallRule.setReturnValue('[ -x ./piper ]', 1)
shellCallRule.setReturnValue('curl --insecure --silent --location --write-out \'%{http_code}\' --output piper \'https://github.com/SAP/jenkins-library/releases/download/testTag/piper\'', '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/download/testTag/piper\'', '200')

piperGoUtils.unstashPiperBin()
assertThat(shellCallRule.shell.size(), is(4))
assertThat(shellCallRule.shell[1].toString(), is('curl --insecure --silent --location --write-out \'%{http_code}\' --output piper \'https://github.com/SAP/jenkins-library/releases/download/testTag/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/testTag/piper\''))
assertThat(shellCallRule.shell[2].toString(), is('chmod +x piper'))
assertThat(shellCallRule.shell[3].toString(), is('./piper version'))
}
Expand All @@ -101,8 +101,8 @@ class PiperGoUtilsTest extends BasePiperTest {

shellCallRule.setReturnValue('[ -x ./piper ]', 1)
shellCallRule.setReturnValue('./piper version', "1.2.3")
shellCallRule.setReturnValue('curl --insecure --silent --location --write-out \'%{http_code}\' --output piper \'https://github.com/SAP/jenkins-library/releases/download/notAvailable/piper\'', '404')
shellCallRule.setReturnValue('curl --insecure --silent --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/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')

// this mocks utils.unstash - mimic stash not existing
helper.registerAllowedMethod("unstash", [String.class], { stashFileName ->
Expand All @@ -112,8 +112,8 @@ class PiperGoUtilsTest extends BasePiperTest {
piperGoUtils.unstashPiperBin()
assertThat(shellCallRule.shell.size(), is(5))
assertThat(shellCallRule.shell[0].toString(), is('[ -x ./piper ]'))
assertThat(shellCallRule.shell[1].toString(), is('curl --insecure --silent --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 --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/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[3].toString(), is('chmod +x piper'))
assertThat(shellCallRule.shell[4].toString(), is ('./piper version'))
}
Expand All @@ -124,8 +124,8 @@ class PiperGoUtilsTest extends BasePiperTest {
piperGoUtils.metaClass.getLibrariesInfo = {-> return [[name: 'piper-lib-os', version: 'notAvailable']]}

shellCallRule.setReturnValue('[ -x ./piper ]', 1)
shellCallRule.setReturnValue('curl --insecure --silent --location --write-out \'%{http_code}\' --output piper \'https://github.com/SAP/jenkins-library/releases/download/notAvailable/piper\'', '404')
shellCallRule.setReturnValue('curl --insecure --silent --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/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')

helper.registerAllowedMethod("unstash", [String.class], { stashFileName ->
return []
Expand All @@ -141,8 +141,8 @@ class PiperGoUtilsTest extends BasePiperTest {
piperGoUtils.metaClass.getLibrariesInfo = {-> return [[name: 'piper-lib-os', version: 'notAvailable']]}

shellCallRule.setReturnValue('[ -x ./piper ]', 1)
shellCallRule.setReturnValue('curl --insecure --silent --location --write-out \'%{http_code}\' --output piper \'https://github.com/SAP/jenkins-library/releases/download/notAvailable/piper\'', '404')
shellCallRule.setReturnValue('curl --insecure --silent --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/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')

helper.registerAllowedMethod("unstash", [String.class], { stashFileName ->
return []
Expand Down

0 comments on commit 54d543a

Please sign in to comment.