blob: 4e2af09d7a841e68c40cc43e17a6d5bcb63fb9ca [file] [log] [blame]
Jakub Josefc5a223a2017-03-01 14:40:08 +01001def common = new com.mirantis.mk.Common()
Filip Pytloun38005aa2017-03-06 10:26:38 +01002def git = new com.mirantis.mk.Git()
Jakub Josefc5a223a2017-03-01 14:40:08 +01003stage("Mirror") {
4 node() {
5 try{
6 def branches = BRANCHES.tokenize(',')
7 def pollBranches = []
8 for (i=0; i < branches.size; i++) {
9 pollBranches.add([name:branches[i]])
10 }
11 dir("target") {
Jakub Josefc2c37172017-06-16 17:53:57 +020012 try{
13 checkout changelog: true, poll: true,
14 scm: [$class: 'GitSCM', branches: pollBranches, doGenerateSubmoduleConfigurations: false,
15 extensions: [[$class: 'CleanCheckout']], submoduleCfg: [], userRemoteConfigs: [[credentialsId: CREDENTIALS_ID, url: TARGET_URL]]]
Jakub Josefe29414f2017-06-17 02:14:35 +020016 } catch(hudson.AbortException e){
Jakub Josefc2c37172017-06-16 17:53:57 +020017 if(e.message.trim().equals("Couldn't find any revision to build. Verify the repository and branch configuration for this job.")){
18 common.warningMsg("Warning: Cannot checkout target repo source repo is empty")
19 } else {
20 throw e
21 }
22 }
Jakub Josefc5a223a2017-03-01 14:40:08 +010023 }
24 dir("source") {
Jakub Josefc2c37172017-06-16 17:53:57 +020025 try{
26 checkout changelog: true, poll: true,
27 scm: [$class: 'GitSCM', branches: pollBranches, doGenerateSubmoduleConfigurations: false,
28 extensions: [[$class: 'CleanCheckout']], submoduleCfg: [], userRemoteConfigs: [[credentialsId: CREDENTIALS_ID, url: SOURCE_URL]]]
Jakub Josefe29414f2017-06-17 02:14:35 +020029 } catch(hudson.AbortException e){
Jakub Josefc2c37172017-06-16 17:53:57 +020030 if(e.message.trim().equals("Couldn't find any revision to build. Verify the repository and branch configuration for this job.")){
31 common.warningMsg("Warning: Cannot checkout source repo source repo is empty")
32 } else {
33 throw e
34 }
35 }
Filip Pytloun38005aa2017-03-06 10:26:38 +010036 git.mirrorGit(SOURCE_URL, TARGET_URL, CREDENTIALS_ID, BRANCHES, true, true, false)
Jakub Josefc5a223a2017-03-01 14:40:08 +010037 }
38 } catch (Throwable e) {
39 // If there was an error or exception thrown, the build failed
40 currentBuild.result = "FAILURE"
Adam Tenglercac28de2017-08-22 15:52:00 +020041 currentBuild.description = e.message
Jakub Josefc5a223a2017-03-01 14:40:08 +010042 throw e
43 } finally {
44 common.sendNotification(currentBuild.result,"",["slack"])
45 }
46 }
Filip Pytloun38005aa2017-03-06 10:26:38 +010047}