Jakub Josef | f2a66e9 | 2017-03-08 17:21:07 +0100 | [diff] [blame] | 1 | /** |
| 2 | * Gerrit gating pipeline |
| 3 | * CREDENTIALS_ID - Gerrit credentails ID |
| 4 | * |
| 5 | **/ |
| 6 | |
| 7 | def common = new com.mirantis.mk.Common() |
| 8 | def gerrit = new com.mirantis.mk.Gerrit() |
Jakub Josef | eda0768 | 2017-03-09 14:50:54 +0100 | [diff] [blame] | 9 | def ssh = new com.mirantis.mk.Ssh() |
Jakub Josef | f2a66e9 | 2017-03-08 17:21:07 +0100 | [diff] [blame] | 10 | node("python") { |
| 11 | try{ |
| 12 | stage("test") { |
Jakub Josef | f2a66e9 | 2017-03-08 17:21:07 +0100 | [diff] [blame] | 13 | wrap([$class: 'AnsiColorBuildWrapper']) { |
Jakub Josef | 4251feb | 2017-03-10 16:10:53 +0100 | [diff] [blame] | 14 | def testJob = String.format("test-%s-%s-latest", JOBS_NAMESPACE, GERRIT_PROJECT) |
| 15 | if(_jobExists(testJob)){ |
| 16 | build job: testJob, parameters: [ |
Jakub Josef | a722d43 | 2017-03-10 12:43:00 +0100 | [diff] [blame] | 17 | [$class: 'StringParameterValue', name: 'GERRIT_BRANCH', value: GERRIT_BRANCH], |
| 18 | [$class: 'StringParameterValue', name: 'GERRIT_NAME', value: GERRIT_NAME], |
| 19 | [$class: 'StringParameterValue', name: 'GERRIT_HOST', value: GERRIT_HOST], |
| 20 | [$class: 'StringParameterValue', name: 'GERRIT_PORT', value: GERRIT_PORT], |
| 21 | [$class: 'StringParameterValue', name: 'GERRIT_PROJECT', value: GERRIT_PROJECT], |
| 22 | [$class: 'StringParameterValue', name: 'GERRIT_REFSPEC', value: GERRIT_REFSPEC] |
| 23 | ] |
| 24 | } |
| 25 | } |
| 26 | } |
Jakub Josef | f2a66e9 | 2017-03-08 17:21:07 +0100 | [diff] [blame] | 27 | } |
| 28 | stage("submit review"){ |
| 29 | ssh.prepareSshAgentKey(CREDENTIALS_ID) |
| 30 | ssh.ensureKnownHosts(GERRIT_HOST) |
Jakub Josef | cec301b | 2017-03-09 15:10:22 +0100 | [diff] [blame] | 31 | ssh.agentSh(String.format("ssh -p 29418 %s@%s gerrit review --submit %s,%s", GERRIT_NAME, GERRIT_HOST, GERRIT_CHANGE_NUMBER, GERRIT_PATCHSET_NUMBER)) |
Jakub Josef | f2a66e9 | 2017-03-08 17:21:07 +0100 | [diff] [blame] | 32 | println(String.format("Gerrit review %s,%s submitted", GERRIT_CHANGE_NUMBER, GERRIT_PATCHSET_NUMBER)) |
Jakub Josef | fd91d1f | 2017-03-08 17:27:41 +0100 | [diff] [blame] | 33 | } |
Jakub Josef | f2a66e9 | 2017-03-08 17:21:07 +0100 | [diff] [blame] | 34 | } catch (Throwable e) { |
| 35 | // If there was an error or exception thrown, the build failed |
| 36 | currentBuild.result = "FAILURE" |
| 37 | throw e |
| 38 | } finally { |
| 39 | common.sendNotification(currentBuild.result,"",["slack"]) |
| 40 | } |
Jakub Josef | 4251feb | 2017-03-10 16:10:53 +0100 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | @NonCPS |
| 44 | def _jobExists(jobName){ |
| 45 | return Jenkins.instance.items.find{it.name.equals(jobName)} |
Jakub Josef | f2a66e9 | 2017-03-08 17:21:07 +0100 | [diff] [blame] | 46 | } |