Filip Pytloun | fcce97c | 2017-03-07 14:06:07 +0100 | [diff] [blame] | 1 | def gerrit = new com.mirantis.mk.Gerrit() |
Filip Pytloun | 6a05730 | 2017-03-07 16:33:30 +0100 | [diff] [blame] | 2 | def common = new com.mirantis.mk.Common() |
Filip Pytloun | 19376a8 | 2017-03-07 12:29:00 +0100 | [diff] [blame] | 3 | |
Filip Pytloun | fcce97c | 2017-03-07 14:06:07 +0100 | [diff] [blame] | 4 | def gerritCredentials |
| 5 | try { |
| 6 | gerritCredentials = CREDENTIALS_ID |
| 7 | } catch (MissingPropertyException e) { |
| 8 | gerritCredentials = "gerrit" |
| 9 | } |
| 10 | |
Jakub Josef | 4612c5d | 2017-03-30 16:04:26 +0200 | [diff] [blame] | 11 | def gerritRef |
| 12 | try { |
| 13 | gerritRef = GERRIT_REFSPEC |
| 14 | } catch (MissingPropertyException e) { |
| 15 | gerritRef = null |
| 16 | } |
| 17 | |
| 18 | def defaultGitRef, defaultGitUrl |
| 19 | try { |
| 20 | defaultGitRef = DEFAULT_GIT_REF |
| 21 | defaultGitUrl = DEFAULT_GIT_URL |
| 22 | } catch (MissingPropertyException e) { |
| 23 | defaultGitRef = null |
| 24 | defaultGitUrl = null |
| 25 | } |
| 26 | def checkouted = false |
| 27 | |
Filip Pytloun | fcce97c | 2017-03-07 14:06:07 +0100 | [diff] [blame] | 28 | try { |
| 29 | stage("Checkout") { |
| 30 | node() { |
Jakub Josef | 4612c5d | 2017-03-30 16:04:26 +0200 | [diff] [blame] | 31 | if (gerritRef) { |
| 32 | // job is triggered by Gerrit |
| 33 | checkouted = gerrit.gerritPatchsetCheckout ([ |
| 34 | credentialsId : gerritCredentials |
| 35 | ]) |
| 36 | // change defaultGit variables if job triggered from Gerrit |
Jakub Josef | 6332677 | 2017-03-30 16:38:11 +0200 | [diff] [blame] | 37 | defaultGitUrl = "${GERRIT_SCHEME}://${GERRIT_NAME}@${GERRIT_HOST}:${GERRIT_PORT}/${GERRIT_PROJECT}" |
Jakub Josef | 4612c5d | 2017-03-30 16:04:26 +0200 | [diff] [blame] | 38 | } else if(defaultGitRef && defaultGitUrl) { |
| 39 | checkouted = gerrit.gerritPatchsetCheckout(defaultGitUrl, defaultGitRef, "HEAD", gerritCredentials) |
| 40 | } |
Filip Pytloun | 840a084 | 2017-03-07 13:54:23 +0100 | [diff] [blame] | 41 | } |
Filip Pytloun | 19376a8 | 2017-03-07 12:29:00 +0100 | [diff] [blame] | 42 | } |
Filip Pytloun | fcce97c | 2017-03-07 14:06:07 +0100 | [diff] [blame] | 43 | |
| 44 | stage("Test") { |
Jakub Josef | 4612c5d | 2017-03-30 16:04:26 +0200 | [diff] [blame] | 45 | if(checkouted){ |
| 46 | def branches = [:] |
| 47 | def testModels = TEST_MODELS.split(',') |
| 48 | for (int i = 0; i < testModels.size(); i++) { |
| 49 | def cluster = testModels[i] |
Jakub Josef | b3f570b | 2017-03-30 17:02:16 +0200 | [diff] [blame] | 50 | def clusterGitUrl = defaultGitUrl.substring(0, defaultGitUrl.lastIndexOf("/") + 1) + cluster |
Jakub Josef | 4612c5d | 2017-03-30 16:04:26 +0200 | [diff] [blame] | 51 | branches["${cluster}"] = { |
| 52 | build job: "test-salt-model-${cluster}", parameters: [ |
Jakub Josef | b3f570b | 2017-03-30 17:02:16 +0200 | [diff] [blame] | 53 | [$class: 'StringParameterValue', name: 'DEFAULT_GIT_URL', value: clusterGitUrl], |
Jakub Josef | 7818a93 | 2017-03-30 17:10:38 +0200 | [diff] [blame] | 54 | [$class: 'StringParameterValue', name: 'DEFAULT_GIT_REF', value: "HEAD"] |
Jakub Josef | 4612c5d | 2017-03-30 16:04:26 +0200 | [diff] [blame] | 55 | ] |
| 56 | } |
| 57 | } |
| 58 | parallel branches |
| 59 | }else{ |
Jakub Josef | 5ce6a36 | 2017-03-31 13:41:17 +0200 | [diff] [blame] | 60 | throw new Exception("Cannot checkout gerrit patchset, GERRIT_REFSPEC and DEFAULT_GIT_REF is null") |
Filip Pytloun | fcce97c | 2017-03-07 14:06:07 +0100 | [diff] [blame] | 61 | } |
Filip Pytloun | fcce97c | 2017-03-07 14:06:07 +0100 | [diff] [blame] | 62 | } |
| 63 | } catch (Throwable e) { |
| 64 | // If there was an error or exception thrown, the build failed |
| 65 | currentBuild.result = "FAILURE" |
| 66 | throw e |
| 67 | } finally { |
| 68 | common.sendNotification(currentBuild.result,"",["slack"]) |
Filip Pytloun | 19376a8 | 2017-03-07 12:29:00 +0100 | [diff] [blame] | 69 | } |