blob: 481dedb34e142bda3e33128f5e99a18cdf57e986 [file] [log] [blame]
Jakub Joseff2a66e92017-03-08 17:21:07 +01001/**
2 * Gerrit gating pipeline
3 * CREDENTIALS_ID - Gerrit credentails ID
4 *
5**/
6
7def common = new com.mirantis.mk.Common()
8def gerrit = new com.mirantis.mk.Gerrit()
Jakub Josefeda07682017-03-09 14:50:54 +01009def ssh = new com.mirantis.mk.Ssh()
Jakub Joseff2a66e92017-03-08 17:21:07 +010010node("python") {
11 try{
12 stage("test") {
Jakub Joseff2a66e92017-03-08 17:21:07 +010013 wrap([$class: 'AnsiColorBuildWrapper']) {
Jakub Josef4251feb2017-03-10 16:10:53 +010014 def testJob = String.format("test-%s-%s-latest", JOBS_NAMESPACE, GERRIT_PROJECT)
15 if(_jobExists(testJob)){
16 build job: testJob, parameters: [
Jakub Josefa722d432017-03-10 12:43:00 +010017 [$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 Joseff2a66e92017-03-08 17:21:07 +010027 }
28 stage("submit review"){
29 ssh.prepareSshAgentKey(CREDENTIALS_ID)
30 ssh.ensureKnownHosts(GERRIT_HOST)
Jakub Josefcec301b2017-03-09 15:10:22 +010031 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 Joseff2a66e92017-03-08 17:21:07 +010032 println(String.format("Gerrit review %s,%s submitted", GERRIT_CHANGE_NUMBER, GERRIT_PATCHSET_NUMBER))
Jakub Joseffd91d1f2017-03-08 17:27:41 +010033 }
Jakub Joseff2a66e92017-03-08 17:21:07 +010034 } 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 Josef4251feb2017-03-10 16:10:53 +010041}
42
43@NonCPS
44def _jobExists(jobName){
45 return Jenkins.instance.items.find{it.name.equals(jobName)}
Jakub Joseff2a66e92017-03-08 17:21:07 +010046}