blob: d3feae094852824cfcbf804ffe454e8ff816a2c6 [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 Josefe3ccb872017-03-23 19:56:07 +010014 // TEST JOBS ARE DISABLED
15 // because you cannot pass GERRIT_REFSPEC like variables to another pipeline
16 if (false && !SKIP_TEST.equals("true")){
Jakub Josef617e1162017-03-21 15:58:27 +010017 wrap([$class: 'AnsiColorBuildWrapper']) {
18 def gerritProjectArray = GERRIT_PROJECT.tokenize("/")
19 def gerritProject = gerritProjectArray[gerritProjectArray.size() - 1]
20 def jobsNamespace = JOBS_NAMESPACE
21 // remove plural s on the end of job namespace
22 if (JOBS_NAMESPACE[JOBS_NAMESPACE.length() - 1].equals("s")){
23 jobsNamespace = JOBS_NAMESPACE.substring(0, JOBS_NAMESPACE.length() - 1)
24 }
Jakub Joseff64c3402017-03-21 18:58:40 +010025 def testJob = String.format("test-%s-%s", jobsNamespace, gerritProject)
Jakub Josef617e1162017-03-21 15:58:27 +010026 if (_jobExists(testJob)) {
27 common.infoMsg("Test job ${testJob} found, running")
28 build job: testJob, parameters: [
29 [$class: 'StringParameterValue', name: 'GERRIT_BRANCH', value: GERRIT_BRANCH],
30 [$class: 'StringParameterValue', name: 'GERRIT_NAME', value: GERRIT_NAME],
31 [$class: 'StringParameterValue', name: 'GERRIT_HOST', value: GERRIT_HOST],
32 [$class: 'StringParameterValue', name: 'GERRIT_PORT', value: GERRIT_PORT],
33 [$class: 'StringParameterValue', name: 'GERRIT_PROJECT', value: GERRIT_PROJECT],
34 [$class: 'StringParameterValue', name: 'GERRIT_REFSPEC', value: GERRIT_REFSPEC]
35 ]
36 } else {
37 common.infoMsg("Test job ${testJob} not found")
38 }
Jakub Josefa722d432017-03-10 12:43:00 +010039 }
Jakub Josef617e1162017-03-21 15:58:27 +010040 } else {
41 common.infoMsg("Test job skipped")
Jakub Josefa722d432017-03-10 12:43:00 +010042 }
Jakub Joseff2a66e92017-03-08 17:21:07 +010043 }
44 stage("submit review"){
45 ssh.prepareSshAgentKey(CREDENTIALS_ID)
46 ssh.ensureKnownHosts(GERRIT_HOST)
Jakub Josefcec301b2017-03-09 15:10:22 +010047 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 +010048 common.infoMsg(String.format("Gerrit review %s,%s submitted", GERRIT_CHANGE_NUMBER, GERRIT_PATCHSET_NUMBER))
Jakub Joseffd91d1f2017-03-08 17:27:41 +010049 }
Jakub Joseff2a66e92017-03-08 17:21:07 +010050 } catch (Throwable e) {
51 // If there was an error or exception thrown, the build failed
52 currentBuild.result = "FAILURE"
53 throw e
54 } finally {
55 common.sendNotification(currentBuild.result,"",["slack"])
56 }
Jakub Josef4251feb2017-03-10 16:10:53 +010057}
58
59@NonCPS
60def _jobExists(jobName){
Jakub Josef253d4482017-03-13 14:04:46 +010061 return Jenkins.instance.items.find{it -> it.name.equals(jobName)}
62}