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 | 617e116 | 2017-03-21 15:58:27 +0100 | [diff] [blame] | 14 | if (!SKIP_TEST.equals("true")){ |
| 15 | 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 Josef | f64c340 | 2017-03-21 18:58:40 +0100 | [diff] [blame^] | 23 | def testJob = String.format("test-%s-%s", jobsNamespace, gerritProject) |
Jakub Josef | 617e116 | 2017-03-21 15:58:27 +0100 | [diff] [blame] | 24 | if (_jobExists(testJob)) { |
| 25 | common.infoMsg("Test job ${testJob} found, running") |
| 26 | build job: testJob, parameters: [ |
| 27 | [$class: 'StringParameterValue', name: 'GERRIT_BRANCH', value: GERRIT_BRANCH], |
| 28 | [$class: 'StringParameterValue', name: 'GERRIT_NAME', value: GERRIT_NAME], |
| 29 | [$class: 'StringParameterValue', name: 'GERRIT_HOST', value: GERRIT_HOST], |
| 30 | [$class: 'StringParameterValue', name: 'GERRIT_PORT', value: GERRIT_PORT], |
| 31 | [$class: 'StringParameterValue', name: 'GERRIT_PROJECT', value: GERRIT_PROJECT], |
| 32 | [$class: 'StringParameterValue', name: 'GERRIT_REFSPEC', value: GERRIT_REFSPEC] |
| 33 | ] |
| 34 | } else { |
| 35 | common.infoMsg("Test job ${testJob} not found") |
| 36 | } |
Jakub Josef | a722d43 | 2017-03-10 12:43:00 +0100 | [diff] [blame] | 37 | } |
Jakub Josef | 617e116 | 2017-03-21 15:58:27 +0100 | [diff] [blame] | 38 | } else { |
| 39 | common.infoMsg("Test job skipped") |
Jakub Josef | a722d43 | 2017-03-10 12:43:00 +0100 | [diff] [blame] | 40 | } |
Jakub Josef | f2a66e9 | 2017-03-08 17:21:07 +0100 | [diff] [blame] | 41 | } |
| 42 | stage("submit review"){ |
| 43 | ssh.prepareSshAgentKey(CREDENTIALS_ID) |
| 44 | ssh.ensureKnownHosts(GERRIT_HOST) |
Jakub Josef | cec301b | 2017-03-09 15:10:22 +0100 | [diff] [blame] | 45 | 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] | 46 | 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] | 47 | } |
Jakub Josef | f2a66e9 | 2017-03-08 17:21:07 +0100 | [diff] [blame] | 48 | } catch (Throwable e) { |
| 49 | // If there was an error or exception thrown, the build failed |
| 50 | currentBuild.result = "FAILURE" |
| 51 | throw e |
| 52 | } finally { |
| 53 | common.sendNotification(currentBuild.result,"",["slack"]) |
| 54 | } |
Jakub Josef | 4251feb | 2017-03-10 16:10:53 +0100 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | @NonCPS |
| 58 | def _jobExists(jobName){ |
Jakub Josef | 253d448 | 2017-03-13 14:04:46 +0100 | [diff] [blame] | 59 | return Jenkins.instance.items.find{it -> it.name.equals(jobName)} |
| 60 | } |