blob: 8cc5031df94675c988218099efe987ad70dd1200 [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 Josef83379312017-03-29 18:12:34 +020014 if (!SKIP_TEST.equals("true")){
Jakub Josef617e1162017-03-21 15:58:27 +010015 wrap([$class: 'AnsiColorBuildWrapper']) {
16 def gerritProjectArray = GERRIT_PROJECT.tokenize("/")
17 def gerritProject = gerritProjectArray[gerritProjectArray.size() - 1]
18 def jobsNamespace = JOBS_NAMESPACE
19 // remove plural s on the end of job namespace
20 if (JOBS_NAMESPACE[JOBS_NAMESPACE.length() - 1].equals("s")){
21 jobsNamespace = JOBS_NAMESPACE.substring(0, JOBS_NAMESPACE.length() - 1)
22 }
Jakub Joseff64c3402017-03-21 18:58:40 +010023 def testJob = String.format("test-%s-%s", jobsNamespace, gerritProject)
Jakub Josef617e1162017-03-21 15:58:27 +010024 if (_jobExists(testJob)) {
25 common.infoMsg("Test job ${testJob} found, running")
26 build job: testJob, parameters: [
Jakub Josefc1c2ec22017-03-31 18:59:03 +020027 [$class: 'StringParameterValue', name: 'DEFAULT_GIT_URL', value: "${GERRIT_SCHEME}://${GERRIT_NAME}@${GERRIT_HOST}:${GERRIT_PORT}/${GERRIT_PROJECT}"],
Jakub Josef83379312017-03-29 18:12:34 +020028 [$class: 'StringParameterValue', name: 'DEFAULT_GIT_REF', value: GERRIT_REFSPEC]
Jakub Josef617e1162017-03-21 15:58:27 +010029 ]
30 } else {
31 common.infoMsg("Test job ${testJob} not found")
32 }
Jakub Josefa722d432017-03-10 12:43:00 +010033 }
Jakub Josef617e1162017-03-21 15:58:27 +010034 } else {
35 common.infoMsg("Test job skipped")
Jakub Josefa722d432017-03-10 12:43:00 +010036 }
Jakub Joseff2a66e92017-03-08 17:21:07 +010037 }
38 stage("submit review"){
39 ssh.prepareSshAgentKey(CREDENTIALS_ID)
40 ssh.ensureKnownHosts(GERRIT_HOST)
Jakub Josefcec301b2017-03-09 15:10:22 +010041 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 +010042 common.infoMsg(String.format("Gerrit review %s,%s submitted", GERRIT_CHANGE_NUMBER, GERRIT_PATCHSET_NUMBER))
Jakub Joseffd91d1f2017-03-08 17:27:41 +010043 }
Jakub Joseff2a66e92017-03-08 17:21:07 +010044 } catch (Throwable e) {
45 // If there was an error or exception thrown, the build failed
46 currentBuild.result = "FAILURE"
47 throw e
48 } finally {
Jakub Josef83379312017-03-29 18:12:34 +020049 //common.sendNotification(currentBuild.result,"",["slack"])
Jakub Joseff2a66e92017-03-08 17:21:07 +010050 }
Jakub Josef4251feb2017-03-10 16:10:53 +010051}
52
53@NonCPS
54def _jobExists(jobName){
Jakub Josef253d4482017-03-13 14:04:46 +010055 return Jenkins.instance.items.find{it -> it.name.equals(jobName)}
56}