Jakub Josef | c5a223a | 2017-03-01 14:40:08 +0100 | [diff] [blame] | 1 | def common = new com.mirantis.mk.Common() |
Filip Pytloun | 38005aa | 2017-03-06 10:26:38 +0100 | [diff] [blame] | 2 | def git = new com.mirantis.mk.Git() |
Jakub Josef | c5a223a | 2017-03-01 14:40:08 +0100 | [diff] [blame] | 3 | stage("Mirror") { |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame^] | 4 | timeout(time: 12, unit: 'HOURS') { |
| 5 | node() { |
| 6 | try{ |
| 7 | def branches = BRANCHES.tokenize(',') |
| 8 | def pollBranches = [] |
| 9 | for (i=0; i < branches.size; i++) { |
| 10 | pollBranches.add([name:branches[i]]) |
| 11 | } |
| 12 | dir("target") { |
| 13 | try{ |
| 14 | checkout changelog: true, poll: true, |
| 15 | scm: [$class: 'GitSCM', branches: pollBranches, doGenerateSubmoduleConfigurations: false, |
| 16 | extensions: [[$class: 'CleanCheckout']], submoduleCfg: [], userRemoteConfigs: [[credentialsId: CREDENTIALS_ID, url: TARGET_URL]]] |
| 17 | } catch(hudson.AbortException e){ |
Jakub Josef | c2c3717 | 2017-06-16 17:53:57 +0200 | [diff] [blame] | 18 | if(e.message.trim().equals("Couldn't find any revision to build. Verify the repository and branch configuration for this job.")){ |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame^] | 19 | common.warningMsg("Warning: Cannot checkout target repo source repo is empty") |
Jakub Josef | c2c3717 | 2017-06-16 17:53:57 +0200 | [diff] [blame] | 20 | } else { |
| 21 | throw e |
| 22 | } |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame^] | 23 | } |
| 24 | } |
| 25 | dir("source") { |
| 26 | try{ |
| 27 | checkout changelog: true, poll: true, |
| 28 | scm: [$class: 'GitSCM', branches: pollBranches, doGenerateSubmoduleConfigurations: false, |
| 29 | extensions: [[$class: 'CleanCheckout']], submoduleCfg: [], userRemoteConfigs: [[credentialsId: CREDENTIALS_ID, url: SOURCE_URL]]] |
| 30 | } catch(hudson.AbortException e){ |
| 31 | if(e.message.trim().equals("Couldn't find any revision to build. Verify the repository and branch configuration for this job.")){ |
| 32 | common.warningMsg("Warning: Cannot checkout source repo source repo is empty") |
| 33 | } else { |
| 34 | throw e |
| 35 | } |
| 36 | } |
| 37 | git.mirrorGit(SOURCE_URL, TARGET_URL, CREDENTIALS_ID, BRANCHES, true, true, false) |
| 38 | } |
| 39 | } catch (Throwable e) { |
| 40 | // If there was an error or exception thrown, the build failed |
| 41 | currentBuild.result = "FAILURE" |
| 42 | currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message |
| 43 | throw e |
| 44 | } finally { |
| 45 | common.sendNotification(currentBuild.result,"",["slack"]) |
Jakub Josef | c5a223a | 2017-03-01 14:40:08 +0100 | [diff] [blame] | 46 | } |
Jakub Josef | c5a223a | 2017-03-01 14:40:08 +0100 | [diff] [blame] | 47 | } |
| 48 | } |
Filip Pytloun | 38005aa | 2017-03-06 10:26:38 +0100 | [diff] [blame] | 49 | } |