Jakub Josef | b08a94b | 2017-08-16 13:54:28 +0200 | [diff] [blame] | 1 | /** |
| 2 | * Git merge branches pipeline |
| 3 | * REPO_URL - Repository URL |
| 4 | * TARGET_BRANCH - Target branch for merging |
| 5 | * SOURCE_BRANCH - The branch will be merged to TARGET_BRANCH |
| 6 | * CREDENTIALS_ID - Used credentails ID |
| 7 | * |
| 8 | **/ |
| 9 | |
| 10 | def common = new com.mirantis.mk.Common() |
| 11 | def git = new com.mirantis.mk.Git() |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 12 | timeout(time: 12, unit: 'HOURS') { |
| 13 | node { |
| 14 | try{ |
| 15 | stage("checkout") { |
| 16 | git.checkoutGitRepository('repo', REPO_URL, TARGET_BRANCH, IMAGE_CREDENTIALS_ID) |
Jakub Josef | b08a94b | 2017-08-16 13:54:28 +0200 | [diff] [blame] | 17 | } |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 18 | stage("merge") { |
| 19 | dir("repo"){ |
| 20 | sh("git fetch origin/${SOURCE_BRANCH} && git merge ${SOURCE_BRANCH} && git push origin ${TARGET_BRANCH}") |
| 21 | } |
| 22 | } |
| 23 | } catch (Throwable e) { |
| 24 | // If there was an error or exception thrown, the build failed |
| 25 | currentBuild.result = "FAILURE" |
| 26 | currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message |
| 27 | throw e |
Jakub Josef | b08a94b | 2017-08-16 13:54:28 +0200 | [diff] [blame] | 28 | } |
Jakub Josef | b08a94b | 2017-08-16 13:54:28 +0200 | [diff] [blame] | 29 | } |
| 30 | } |
| 31 | |