Skip to content
This repository was archived by the owner on Oct 28, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/test/groovy/GsutilStepTests.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,22 @@ class GsutilStepTests extends ApmBasePipelineTest {
}

@Test
void test_without_gh_installed_by_default_no_wget() throws Exception {
void test_without_gh_installed_by_default_no_wget_no_curl() throws Exception {
helper.registerAllowedMethod('isInstalled', [Map.class], { return false })
script.call(command: 'cp', credentialsId: 'foo')
printCallStack()
assertFalse(assertMethodCallContainsPattern('sh', 'wget -q -O'))
assertFalse(assertMethodCallContainsPattern('sh', 'curl'))
assertJobStatusSuccess()
}

@Test
void test_without_gh_installed_by_default_no_wget() throws Exception {
helper.registerAllowedMethod('isInstalled', [Map.class], { m -> return !(m.tool.equals('wget') || m.tool.equals('gsutil'))})
script.call(command: 'cp', credentialsId: 'foo')
printCallStack()
assertFalse(assertMethodCallContainsPattern('sh', 'wget -q -O gsutil.tar.gz'))
assertTrue(assertMethodCallContainsPattern('sh', 'curl -sSLo gsutil.tar.gz --retry 3 --retry-delay 2 --max-time 10'))
assertJobStatusSuccess()
}

Expand Down
27 changes: 22 additions & 5 deletions vars/gsutil.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,33 @@ def call(Map args = [:]) {
def downloadInstaller(where) {
def url = googleCloudSdkURL()
def tarball = "gsutil.${isUnix() ? 'tar.gz' : 'zip'}"

dir(where) {
if (!downloadWithWget(tarball, url)) {
downloadWithCurl(tarball, url)
}
uncompress(tarball)
}
}

def downloadWithWget(tarball, url) {
if(isInstalled(tool: 'wget', flag: '--version')) {
dir(where) {
retryWithSleep(retries: 3, seconds: 5, backoff: true) {
cmd(label: 'download gsutil', script: "wget -q -O ${tarball} ${url}")
uncompress(tarball)
}
retryWithSleep(retries: 3, seconds: 5, backoff: true) {
cmd(label: 'download gsutil', script: "wget -q -O ${tarball} ${url}")
}
return true
} else {
log(level: 'WARN', text: 'gsutil: wget is not available. gsutil will not be installed then.')
}
return false
}

def downloadWithCurl(tarball, url) {
if(isInstalled(tool: 'curl', flag: '--version')) {
cmd(label: 'download gsutil', script: "curl -sSLo ${tarball} --retry 3 --retry-delay 2 --max-time 10 ${url}")
} else {
log(level: 'WARN', text: 'gsutil: curl is not available. gsutil will not be installed then.')
}
}

def googleCloudSdkURL() {
Expand Down