blob: 21d72bf05ce63bb462f88f7ff6ea982596dd1a15 [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") {
Jakub Josefa63f9862018-01-11 17:58:38 +01004 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 Josefc2c37172017-06-16 17:53:57 +020018 if(e.message.trim().equals("Couldn't find any revision to build. Verify the repository and branch configuration for this job.")){
Jakub Josefa63f9862018-01-11 17:58:38 +010019 common.warningMsg("Warning: Cannot checkout target repo source repo is empty")
Jakub Josefc2c37172017-06-16 17:53:57 +020020 } else {
21 throw e
22 }
Jakub Josefa63f9862018-01-11 17:58:38 +010023 }
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 {
Sergey Otpuschennikovacab1dc2018-02-06 19:02:45 +040045 if(env.getEnvironment().containsKey("NOTIFICATION_RECIPIENTS")){
46 common.sendNotification(currentBuild.result,"",["slack", "email"], ["failed"], env["JOB_NAME"], env["BUILD_NUMBER"], env["BUILD_URL"], "MCP jenkins", env["NOTIFICATION_RECIPIENTS"])
47 }else{
48 common.sendNotification(currentBuild.result, "", ["slack"])
49 }
Jakub Josefc5a223a2017-03-01 14:40:08 +010050 }
Jakub Josefc5a223a2017-03-01 14:40:08 +010051 }
52 }
Filip Pytloun38005aa2017-03-06 10:26:38 +010053}