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