| 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 = [] | 
| Dmitry Burmistrov | ea84e31 | 2018-06-29 15:04:50 +0400 | [diff] [blame] | 9 | for (i=0; i < branches.size(); i++) { | 
| Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 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 { | 
| Sergey Otpuschennikov | acab1dc | 2018-02-06 19:02:45 +0400 | [diff] [blame] | 45 | 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 Josef | c5a223a | 2017-03-01 14:40:08 +0100 | [diff] [blame] | 50 | } | 
| Jakub Josef | c5a223a | 2017-03-01 14:40:08 +0100 | [diff] [blame] | 51 | } | 
|  | 52 | } | 
| Filip Pytloun | 38005aa | 2017-03-06 10:26:38 +0100 | [diff] [blame] | 53 | } |