mirror of
https://github.com/SAP/jenkins-library.git
synced 2025-02-21 19:48:53 +02:00
More resilient handling of download errors for piper bin (#1147)
* fix #1114 * Update test/groovy/com/sap/piper/PiperGoUtilsTest.groovy * add log output
This commit is contained in:
parent
d5bc8db50e
commit
321f8fbbc1
@ -52,11 +52,16 @@ class PiperGoUtils implements Serializable {
|
||||
|
||||
private boolean downloadGoBinary(url) {
|
||||
|
||||
def httpStatus = steps.sh(returnStdout: true, script: "curl --insecure --silent --location --write-out '%{http_code}' --output ./piper '${url}'")
|
||||
try {
|
||||
def httpStatus = steps.sh(returnStdout: true, script: "curl --insecure --silent --location --write-out '%{http_code}' --output ./piper '${url}'")
|
||||
|
||||
if (httpStatus == '200') {
|
||||
steps.sh(script: 'chmod +x ./piper')
|
||||
return true
|
||||
if (httpStatus == '200') {
|
||||
steps.sh(script: 'chmod +x ./piper')
|
||||
return true
|
||||
}
|
||||
} catch(err) {
|
||||
//nothing to do since error should just result in downloaded=false
|
||||
steps.echo "Failed downloading Piper go binary with error '${err}'"
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.sap.piper
|
||||
|
||||
import hudson.AbortException
|
||||
import org.junit.Before
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
@ -110,7 +111,7 @@ class PiperGoUtilsTest extends BasePiperTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testDownloadFailed() {
|
||||
void testDownloadFailedWithErrorCode() {
|
||||
def piperGoUtils = new PiperGoUtils(nullScript, utils)
|
||||
piperGoUtils.metaClass.getLibrariesInfo = {-> return [[name: 'piper-lib-os', version: 'notAvailable']]}
|
||||
|
||||
@ -124,6 +125,36 @@ class PiperGoUtilsTest extends BasePiperTest {
|
||||
exception.expectMessage(containsString('Download of Piper go binary failed'))
|
||||
piperGoUtils.unstashPiperBin()
|
||||
}
|
||||
|
||||
@Test
|
||||
void testDownloadFailedWithHTTPCode() {
|
||||
def piperGoUtils = new PiperGoUtils(nullScript, utils)
|
||||
piperGoUtils.metaClass.getLibrariesInfo = {-> return [[name: 'piper-lib-os', version: 'notAvailable']]}
|
||||
|
||||
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')
|
||||
|
||||
helper.registerAllowedMethod("unstash", [String.class], { stashFileName ->
|
||||
return []
|
||||
})
|
||||
|
||||
exception.expectMessage(containsString('Download of Piper go binary failed'))
|
||||
piperGoUtils.unstashPiperBin()
|
||||
}
|
||||
|
||||
@Test
|
||||
void testDownloadFailedWithError() {
|
||||
def piperGoUtils = new PiperGoUtils(nullScript, utils)
|
||||
piperGoUtils.metaClass.getLibrariesInfo = {-> return [[name: 'piper-lib-os', version: 'notAvailable']]}
|
||||
|
||||
helper.registerAllowedMethod('sh', [Map.class], {m -> throw new AbortException('download failed')})
|
||||
|
||||
helper.registerAllowedMethod("unstash", [String.class], { stashFileName ->
|
||||
return []
|
||||
})
|
||||
|
||||
exception.expectMessage(containsString('Download of Piper go binary failed'))
|
||||
piperGoUtils.unstashPiperBin()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user