blob: 871a35573e35ebc10dd3a7ceb11c086c51a5ad85 [file] [log] [blame]
Jakub Joseff2a66e92017-03-08 17:21:07 +01001/**
2 * Gerrit gating pipeline
3 * CREDENTIALS_ID - Gerrit credentails ID
Jakub Josefb62d00a2017-03-13 12:21:40 +01004 * JOBS_NAMESPACE - Gerrit gating jobs namespace (mk, contrail, ...)
Jakub Joseff2a66e92017-03-08 17:21:07 +01005 *
6**/
7
8def common = new com.mirantis.mk.Common()
9def gerrit = new com.mirantis.mk.Gerrit()
Jakub Josefeda07682017-03-09 14:50:54 +010010def ssh = new com.mirantis.mk.Ssh()
Jakub Joseff2a66e92017-03-08 17:21:07 +010011node("python") {
12 try{
13 stage("test") {
Jakub Joseff2a66e92017-03-08 17:21:07 +010014 wrap([$class: 'AnsiColorBuildWrapper']) {
Jakub Josefb62d00a2017-03-13 12:21:40 +010015 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 Josefa722d432017-03-10 12:43:00 +010028 }
29 }
Jakub Joseff2a66e92017-03-08 17:21:07 +010030 }
31 stage("submit review"){
32 ssh.prepareSshAgentKey(CREDENTIALS_ID)
33 ssh.ensureKnownHosts(GERRIT_HOST)
Jakub Josefcec301b2017-03-09 15:10:22 +010034 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 Josefb62d00a2017-03-13 12:21:40 +010035 common.infoMsg(String.format("Gerrit review %s,%s submitted", GERRIT_CHANGE_NUMBER, GERRIT_PATCHSET_NUMBER))
Jakub Joseffd91d1f2017-03-08 17:27:41 +010036 }
Jakub Joseff2a66e92017-03-08 17:21:07 +010037 } 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 Josef4251feb2017-03-10 16:10:53 +010044}
45
46@NonCPS
47def _jobExists(jobName){
48 return Jenkins.instance.items.find{it.name.equals(jobName)}
Jakub Joseff2a66e92017-03-08 17:21:07 +010049}