blob: 7911d37aa19ddef7a1304494d854823d61e4d79e [file] [log] [blame]
Richard Felkl91ba0c62018-01-25 15:11:38 +01001/**
2 *
3 * Create debmirror package pipeline
4 *
5 * Expected parameters:
6 * MIRROR_NAME - Name of the mirror
7 * MIRROR_URL - URL of mirror
8 * ROOT - Root directory of the upstream location
9 * METHOD - rsync or http
10 * DEBMIRROR_ARGS - args for debmirror comand
11 * UPLOAD_URL - URL to upload TAR to
12 */
13
14// Load shared libs
15def common = new com.mirantis.mk.Common()
16
17timeout(time: 12, unit: 'HOURS') {
18 node("python&&disk-xl") {
19 try {
20 def workspace = common.getWorkspace()
21 if(METHOD == "rsync"){
22 ROOT = ":mirror/${ROOT}"
23 }
24 stage("Create mirror"){
25 def mirrordir="${workspace}/mirror"
26 def debmlog="${workspace}/mirror_${MIRROR_NAME}_log"
27
28 sh "debmirror --verbose --method=${METHOD} --progress --host=${MIRROR_URL} --root=${ROOT} ${DEBMIRROR_ARGS} ${mirrordir}/${MIRROR_NAME} 2>&1 | tee -a ${debmlog}"
29
30 sh "tar -czvf ${workspace}/${MIRROR_NAME}.tar.gz -C ${mirrordir}/${MIRROR_NAME} ."
31 }
32
33 stage("Upload mirror"){
34 common.retry(3, 5, {
35 uploadImageStatus = sh(script: "curl -f -T ${workspace}/${MIRROR_NAME}.tar.gz ${UPLOAD_URL}", returnStatus: true)
36 if(uploadImageStatus!=0){
37 throw new Exception("Image upload failed")
38 }
39 })
40 }
41
42 } catch (Throwable e) {
43 // If there was an error or exception thrown, the build failed
44 currentBuild.result = "FAILURE"
45 throw e
46 }finally {
47 stage("Cleanup"){
48 sh "rm -rf ${workspace}/*"
49 }
50 }
51 }
52}