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