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