blob: 411edfcfc9795fe54ce14ffe851ffd264ba3e566 [file] [log] [blame]
Filip Pytlounfcce97c2017-03-07 14:06:07 +01001def gerrit = new com.mirantis.mk.Gerrit()
Filip Pytloun6a057302017-03-07 16:33:30 +01002def common = new com.mirantis.mk.Common()
Filip Pytloun19376a82017-03-07 12:29:00 +01003
Filip Pytlounfcce97c2017-03-07 14:06:07 +01004def gerritCredentials
5try {
6 gerritCredentials = CREDENTIALS_ID
7} catch (MissingPropertyException e) {
8 gerritCredentials = "gerrit"
9}
10
Jakub Josef4612c5d2017-03-30 16:04:26 +020011def gerritRef
12try {
13 gerritRef = GERRIT_REFSPEC
14} catch (MissingPropertyException e) {
15 gerritRef = null
16}
17
18def defaultGitRef, defaultGitUrl
19try {
20 defaultGitRef = DEFAULT_GIT_REF
21 defaultGitUrl = DEFAULT_GIT_URL
22} catch (MissingPropertyException e) {
23 defaultGitRef = null
24 defaultGitUrl = null
25}
26def checkouted = false
Jakub Joseffcb615e2017-04-10 14:34:40 +020027def merged = false
chnydad66d6fa2017-06-22 09:34:43 +020028def systemRefspec = "HEAD"
Filip Pytlounfcce97c2017-03-07 14:06:07 +010029try {
30 stage("Checkout") {
31 node() {
Jakub Josef4612c5d2017-03-30 16:04:26 +020032 if (gerritRef) {
33 // job is triggered by Gerrit
Jakub Joseffcb615e2017-04-10 14:34:40 +020034 // test if change aren't already merged
Jakub Josef64045e92017-04-10 17:01:59 +020035 def gerritChange = gerrit.getGerritChange(GERRIT_NAME, GERRIT_HOST, GERRIT_CHANGE_NUMBER, gerritCredentials)
Jakub Joseffcb615e2017-04-10 14:34:40 +020036 merged = gerritChange.status == "MERGED"
37 if(!merged){
38 checkouted = gerrit.gerritPatchsetCheckout ([
39 credentialsId : gerritCredentials
40 ])
chnydad66d6fa2017-06-22 09:34:43 +020041 systemRefspec = GERRIT_REFSPEC
Jakub Joseffcb615e2017-04-10 14:34:40 +020042 }
Jakub Josef4612c5d2017-03-30 16:04:26 +020043 // change defaultGit variables if job triggered from Gerrit
Jakub Josef63326772017-03-30 16:38:11 +020044 defaultGitUrl = "${GERRIT_SCHEME}://${GERRIT_NAME}@${GERRIT_HOST}:${GERRIT_PORT}/${GERRIT_PROJECT}"
Jakub Josef4612c5d2017-03-30 16:04:26 +020045 } else if(defaultGitRef && defaultGitUrl) {
46 checkouted = gerrit.gerritPatchsetCheckout(defaultGitUrl, defaultGitRef, "HEAD", gerritCredentials)
47 }
Filip Pytloun840a0842017-03-07 13:54:23 +010048 }
Filip Pytloun19376a82017-03-07 12:29:00 +010049 }
Filip Pytlounfcce97c2017-03-07 14:06:07 +010050
51 stage("Test") {
Jakub Joseffcb615e2017-04-10 14:34:40 +020052 if(merged){
53 common.successMsg("Gerrit change is already merged, no need to test them")
Jakub Josef4612c5d2017-03-30 16:04:26 +020054 }else{
Jakub Joseffcb615e2017-04-10 14:34:40 +020055 if(checkouted){
56 def branches = [:]
57 def testModels = TEST_MODELS.split(',')
58 for (int i = 0; i < testModels.size(); i++) {
59 def cluster = testModels[i]
60 def clusterGitUrl = defaultGitUrl.substring(0, defaultGitUrl.lastIndexOf("/") + 1) + cluster
61 branches["${cluster}"] = {
62 build job: "test-salt-model-${cluster}", parameters: [
63 [$class: 'StringParameterValue', name: 'DEFAULT_GIT_URL', value: clusterGitUrl],
chnyda19eee6a2017-06-22 17:13:11 +020064 [$class: 'StringParameterValue', name: 'DEFAULT_GIT_REF', value: "HEAD"],
chnydad66d6fa2017-06-22 09:34:43 +020065 [$class: 'StringParameterValue', name: 'SYSTEM_GIT_URL', value: defaultGitUrl],
66 [$class: 'StringParameterValue', name: 'SYSTEM_GIT_REF', value: systemRefspec]
Jakub Joseffcb615e2017-04-10 14:34:40 +020067 ]
68 }
69 }
70 parallel branches
71 }else{
72 throw new Exception("Cannot checkout gerrit patchset, GERRIT_REFSPEC and DEFAULT_GIT_REF is null")
73 }
Filip Pytlounfcce97c2017-03-07 14:06:07 +010074 }
Filip Pytlounfcce97c2017-03-07 14:06:07 +010075 }
76} catch (Throwable e) {
77 // If there was an error or exception thrown, the build failed
78 currentBuild.result = "FAILURE"
Jakub Josefd2efd7d2017-08-22 17:49:57 +020079 currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message
Filip Pytlounfcce97c2017-03-07 14:06:07 +010080 throw e
81} finally {
82 common.sendNotification(currentBuild.result,"",["slack"])
Filip Pytloun19376a82017-03-07 12:29:00 +010083}