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 | |
azvyagintsev | b266ad2 | 2018-09-11 12:11:11 +0300 | [diff] [blame] | 4 | |
azvyagintsev | 2f10cf5 | 2018-09-20 11:30:47 +0300 | [diff] [blame^] | 5 | def slaveNode = env.SLAVE_NODE ?: 'python&&docker' |
| 6 | def gerritCredentials = env.CREDENTIALS_ID ?: 'gerrit' |
azvyagintsev | b266ad2 | 2018-09-11 12:11:11 +0300 | [diff] [blame] | 7 | |
azvyagintsev | 2f10cf5 | 2018-09-20 11:30:47 +0300 | [diff] [blame^] | 8 | def gerritRef = env.GERRIT_REFSPEC ?: null |
| 9 | def defaultGitRef = env.DEFAULT_GIT_REF ?: null |
| 10 | def defaultGitUrl = env.DEFAULT_GIT_URL ?: null |
Filip Pytloun | fcce97c | 2017-03-07 14:06:07 +0100 | [diff] [blame] | 11 | |
Jakub Josef | 4612c5d | 2017-03-30 16:04:26 +0200 | [diff] [blame] | 12 | def checkouted = false |
Jakub Josef | fcb615e | 2017-04-10 14:34:40 +0200 | [diff] [blame] | 13 | def merged = false |
chnyda | d66d6fa | 2017-06-22 09:34:43 +0200 | [diff] [blame] | 14 | def systemRefspec = "HEAD" |
Vasyl Saienko | 6c3cd6b | 2018-06-26 14:02:51 +0300 | [diff] [blame] | 15 | def formulasRevision = 'testing' |
azvyagintsev | 2f10cf5 | 2018-09-20 11:30:47 +0300 | [diff] [blame^] | 16 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 17 | timeout(time: 12, unit: 'HOURS') { |
azvyagintsev | b266ad2 | 2018-09-11 12:11:11 +0300 | [diff] [blame] | 18 | node(slaveNode) { |
azvyagintsev | 0c97ffc | 2018-09-11 11:55:58 +0300 | [diff] [blame] | 19 | try { |
| 20 | stage("Checkout") { |
| 21 | if (gerritRef) { |
| 22 | // job is triggered by Gerrit |
| 23 | // test if change aren't already merged |
| 24 | def gerritChange = gerrit.getGerritChange(GERRIT_NAME, GERRIT_HOST, GERRIT_CHANGE_NUMBER, gerritCredentials) |
| 25 | merged = gerritChange.status == "MERGED" |
| 26 | if (!merged) { |
| 27 | checkouted = gerrit.gerritPatchsetCheckout([ |
| 28 | credentialsId: gerritCredentials |
| 29 | ]) |
| 30 | systemRefspec = GERRIT_REFSPEC |
| 31 | } |
| 32 | // change defaultGit variables if job triggered from Gerrit |
| 33 | defaultGitUrl = "${GERRIT_SCHEME}://${GERRIT_NAME}@${GERRIT_HOST}:${GERRIT_PORT}/${GERRIT_PROJECT}" |
| 34 | } else if (defaultGitRef && defaultGitUrl) { |
| 35 | checkouted = gerrit.gerritPatchsetCheckout(defaultGitUrl, defaultGitRef, "HEAD", gerritCredentials) |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | stage("Test") { |
| 40 | if (merged) { |
| 41 | common.successMsg("Gerrit change is already merged, no need to test them") |
| 42 | } else { |
| 43 | if (checkouted) { |
| 44 | |
| 45 | def documentationOnly = false |
| 46 | if (gerritRef) { |
| 47 | documentationOnly = sh(script: "git diff-tree --no-commit-id --name-only -r HEAD | grep -v .releasenotes", returnStatus: true) == 1 |
| 48 | } |
| 49 | |
| 50 | sh("git diff-tree --no-commit-id --diff-filter=d --name-only -r HEAD | grep .yml | xargs -I {} python -c \"import yaml; yaml.load(open('{}', 'r'))\" \\;") |
| 51 | |
| 52 | def branches = [:] |
| 53 | def testModels = documentationOnly ? [] : TEST_MODELS.split(',') |
azvyagintsev | 2f10cf5 | 2018-09-20 11:30:47 +0300 | [diff] [blame^] | 54 | if (['master'].contains(env.GERRIT_BRANCH)) { |
| 55 | for (int i = 0; i < testModels.size(); i++) { |
| 56 | def cluster = testModels[i] |
| 57 | def clusterGitUrl = defaultGitUrl.substring(0, defaultGitUrl.lastIndexOf("/") + 1) + cluster |
| 58 | branches["${cluster}"] = { |
| 59 | build job: "test-salt-model-${cluster}", parameters: [ |
| 60 | [$class: 'StringParameterValue', name: 'DEFAULT_GIT_URL', value: clusterGitUrl], |
| 61 | [$class: 'StringParameterValue', name: 'DEFAULT_GIT_REF', value: "HEAD"], |
| 62 | [$class: 'StringParameterValue', name: 'SYSTEM_GIT_URL', value: defaultGitUrl], |
| 63 | [$class: 'StringParameterValue', name: 'SYSTEM_GIT_REF', value: systemRefspec], |
| 64 | [$class: 'StringParameterValue', name: 'FORMULAS_REVISION', value: formulasRevision], |
| 65 | ] |
| 66 | } |
azvyagintsev | 0c97ffc | 2018-09-11 11:55:58 +0300 | [diff] [blame] | 67 | } |
azvyagintsev | 2f10cf5 | 2018-09-20 11:30:47 +0300 | [diff] [blame^] | 68 | } else { |
| 69 | common.warningMsg("Tests for ${testModels} skipped!") |
azvyagintsev | 0c97ffc | 2018-09-11 11:55:58 +0300 | [diff] [blame] | 70 | } |
| 71 | branches["cookiecutter"] = { |
| 72 | build job: "test-mk-cookiecutter-templates", parameters: [ |
azvyagintsev | b266ad2 | 2018-09-11 12:11:11 +0300 | [diff] [blame] | 73 | [$class: 'StringParameterValue', name: 'RECLASS_SYSTEM_URL', value: defaultGitUrl], |
| 74 | [$class: 'StringParameterValue', name: 'RECLASS_SYSTEM_GIT_REF', value: systemRefspec], |
azvyagintsev | 0c97ffc | 2018-09-11 11:55:58 +0300 | [diff] [blame] | 75 | [$class: 'StringParameterValue', name: 'DISTRIB_REVISION', value: formulasRevision] |
| 76 | |
| 77 | ] |
| 78 | } |
| 79 | parallel branches |
| 80 | } else { |
azvyagintsev | 2f10cf5 | 2018-09-20 11:30:47 +0300 | [diff] [blame^] | 81 | error("Cannot checkout gerrit patchset, GERRIT_REFSPEC and DEFAULT_GIT_REF is null") |
azvyagintsev | 0c97ffc | 2018-09-11 11:55:58 +0300 | [diff] [blame] | 82 | } |
| 83 | } |
| 84 | } |
| 85 | } catch (Throwable e) { |
azvyagintsev | 0c97ffc | 2018-09-11 11:55:58 +0300 | [diff] [blame] | 86 | currentBuild.result = "FAILURE" |
| 87 | currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message |
| 88 | throw e |
| 89 | } finally { |
| 90 | common.sendNotification(currentBuild.result, "", ["slack"]) |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 91 | } |
Filip Pytloun | fcce97c | 2017-03-07 14:06:07 +0100 | [diff] [blame] | 92 | } |
Filip Pytloun | 19376a8 | 2017-03-07 12:29:00 +0100 | [diff] [blame] | 93 | } |