-
Notifications
You must be signed in to change notification settings - Fork 46
/
sync-http-to-s3.groovy
49 lines (45 loc) · 1.97 KB
/
sync-http-to-s3.groovy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/**
* File upload to AWS S3 pipeline
*
* Expected parameters:
* DEST S3 bucket to upload files to (e.g. s3://images-mirantis-com)
* IMAGE The image with s4cmd utility installed
* SOURCE The source URL to download files from (e.g. http://images.mcp.mirantis.net)
* FILENAMES Relative path to files. (SOURCE and FILENAMES values are being
* concantenated to form URL to download files from.)
* FORCE_UPLOAD Force file upload (will overwrite existing destination file)
*/
def common = new com.mirantis.mk.Common()
def s4cmdOpts = ' --sync-check '
Boolean forceUpload = (env.FORCE_UPLOAD ?: false).toBoolean()
def wgetTries = env.WGET_TRIES ?: '50'
node("docker") {
stage('Prepare') {
img = docker.image(IMAGE)
img.pull()
}
stage('Upload') {
FILENAMES.split().each { filenamePath ->
url = "${SOURCE}/${filenamePath}"
filename = filenamePath.tokenize('/')[-1]
opts = s4cmdOpts
if(filenamePath.contains('stable') || forceUpload) {
common.warningMsg("Going to ovveride ${filenamePath}")
opts = opts + '--force'
}
img.withRun("--entrypoint='/bin/bash'") { c ->
withCredentials([[$class: 'UsernamePasswordMultiBinding', credentialsId: 'aws-s3',
usernameVariable: 'S3_ACCESS_KEY', passwordVariable: 'S3_SECRET_KEY']]) {
img.inside("-e S3_ACCESS_KEY=${S3_ACCESS_KEY} -e S3_SECRET_KEY=${S3_SECRET_KEY}") {
common.retry(3, 5) {
sh(script: "wget --progress=dot:giga --tries=${wgetTries} -O ${filename} ${url}", returnStdout: true)
sh(script: "/usr/local/bin/s4cmd put ${opts} ${filename} ${DEST}/${filenamePath}", returnStdout: true)
}
}
}
}
sh("rm ${filename}")
}
}
deleteDir()
}