[upload_images_to_s3] Update job
Changes:
* add possiblity to process files within directories
* add FORCE_UPLOAD parameter so destination file can be overwritten
Change-Id: I6069142383e937dbd0b7d133b1c087194bd9359b
Related-PROD: https://mirantis.jira.com/browse/RE-441
diff --git a/sync-http-to-s3.groovy b/sync-http-to-s3.groovy
index 3eeaece..976272c 100644
--- a/sync-http-to-s3.groovy
+++ b/sync-http-to-s3.groovy
@@ -1,5 +1,6 @@
def common = new com.mirantis.mk.Common()
-s4cmdOpts = ' --sync-check '
+def s4cmdOpts = ' --sync-check '
+Boolean forceUpload = (env.FORCE_UPLOAD ?: false).toBoolean()
node("docker") {
stage('Prepare') {
@@ -7,20 +8,21 @@
img.pull()
}
stage('Upload') {
- FILENAMES.split().each { filename ->
- url = "${SOURCE}/${filename}"
+ FILENAMES.split().each { filenamePath ->
+ url = "${SOURCE}/${filenamePath}"
+ filename = filenamePath.tokenize('/')[-1]
opts = s4cmdOpts
- if(filename.contains('stable')){
- common.warningMsg("Going to ovveride ${filename}")
+ 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',
+ 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=50 -O ${filename} ${url}", returnStdout: true)
- sh(script: "/usr/local/bin/s4cmd put ${opts} ${filename} ${DEST}/${filename}", returnStdout: true)
+ sh(script: "/usr/local/bin/s4cmd put ${opts} ${filename} ${DEST}/${filenamePath}", returnStdout: true)
}
}
}