blob: e9b83af113648fcb54b85ee9f82f0ab2718dcfb7 [file] [log] [blame]
Ivan Udovichenko24af4152020-10-29 20:57:08 +03001/**
2 * File upload to AWS S3 pipeline
3 *
4 * Expected parameters:
5 * DEST S3 bucket to upload files to (e.g. s3://images-mirantis-com)
6 * IMAGE The image with s4cmd utility installed
7 * SOURCE The source URL to download files from (e.g. http://images.mcp.mirantis.net)
8 * FILENAMES Relative path to files. (SOURCE and FILENAMES values are being
9 * concantenated to form URL to download files from.)
10 * FORCE_UPLOAD Force file upload (will overwrite existing destination file)
11 */
12
Kirill Mashchenkoda535892018-09-05 11:05:52 +030013def common = new com.mirantis.mk.Common()
Ivan Udovichenko26208ed2020-10-29 16:59:09 +030014def s4cmdOpts = ' --sync-check '
15Boolean forceUpload = (env.FORCE_UPLOAD ?: false).toBoolean()
Ivan Udovichenko24af4152020-10-29 20:57:08 +030016def wgetTries = env.WGET_TRIES ?: '50'
Kirill Mashchenkoda535892018-09-05 11:05:52 +030017
18node("docker") {
19 stage('Prepare') {
20 img = docker.image(IMAGE)
21 img.pull()
22 }
23 stage('Upload') {
Ivan Udovichenko26208ed2020-10-29 16:59:09 +030024 FILENAMES.split().each { filenamePath ->
25 url = "${SOURCE}/${filenamePath}"
26 filename = filenamePath.tokenize('/')[-1]
azvyagintsevac363ef2018-11-23 20:13:08 +020027 opts = s4cmdOpts
Ivan Udovichenko26208ed2020-10-29 16:59:09 +030028 if(filenamePath.contains('stable') || forceUpload) {
29 common.warningMsg("Going to ovveride ${filenamePath}")
azvyagintsevac363ef2018-11-23 20:13:08 +020030 opts = opts + '--force'
31 }
Kirill Mashchenkoda535892018-09-05 11:05:52 +030032 img.withRun("--entrypoint='/bin/bash'") { c ->
Ivan Udovichenko26208ed2020-10-29 16:59:09 +030033 withCredentials([[$class: 'UsernamePasswordMultiBinding', credentialsId: 'aws-s3',
Kirill Mashchenkoda535892018-09-05 11:05:52 +030034 usernameVariable: 'S3_ACCESS_KEY', passwordVariable: 'S3_SECRET_KEY']]) {
35 img.inside("-e S3_ACCESS_KEY=${S3_ACCESS_KEY} -e S3_SECRET_KEY=${S3_SECRET_KEY}") {
36 common.retry(3, 5) {
Ivan Udovichenko24af4152020-10-29 20:57:08 +030037 sh(script: "wget --progress=dot:giga --tries=${wgetTries} -O ${filename} ${url}", returnStdout: true)
Ivan Udovichenko26208ed2020-10-29 16:59:09 +030038 sh(script: "/usr/local/bin/s4cmd put ${opts} ${filename} ${DEST}/${filenamePath}", returnStdout: true)
Kirill Mashchenkoda535892018-09-05 11:05:52 +030039 }
40 }
41 }
42
43
44 }
45 sh("rm ${filename}")
46 }
47 }
48 deleteDir()
49}