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") { |
| 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 Josef | c2c3717 | 2017-06-16 17:53:57 +0200 | [diff] [blame] | 12 | 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]]] |
| 16 | } catch(AbortException e){ |
| 17 | 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 Josef | c5a223a | 2017-03-01 14:40:08 +0100 | [diff] [blame] | 23 | } |
| 24 | dir("source") { |
Jakub Josef | c2c3717 | 2017-06-16 17:53:57 +0200 | [diff] [blame] | 25 | 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]]] |
| 29 | } catch(AbortException e){ |
| 30 | 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 Pytloun | 38005aa | 2017-03-06 10:26:38 +0100 | [diff] [blame] | 36 | git.mirrorGit(SOURCE_URL, TARGET_URL, CREDENTIALS_ID, BRANCHES, true, true, false) |
Jakub Josef | c5a223a | 2017-03-01 14:40:08 +0100 | [diff] [blame] | 37 | } |
| 38 | } catch (Throwable e) { |
| 39 | // If there was an error or exception thrown, the build failed |
| 40 | currentBuild.result = "FAILURE" |
| 41 | throw e |
| 42 | } finally { |
| 43 | common.sendNotification(currentBuild.result,"",["slack"]) |
| 44 | } |
| 45 | } |
Filip Pytloun | 38005aa | 2017-03-06 10:26:38 +0100 | [diff] [blame] | 46 | } |