blob: d6e38e45f313c71c3c62bad3e12eca0e121523be [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
azvyagintsevb266ad22018-09-11 12:11:11 +03004
azvyagintsev2f10cf52018-09-20 11:30:47 +03005def slaveNode = env.SLAVE_NODE ?: 'python&&docker'
6def gerritCredentials = env.CREDENTIALS_ID ?: 'gerrit'
azvyagintsevb266ad22018-09-11 12:11:11 +03007
azvyagintsev2f10cf52018-09-20 11:30:47 +03008def gerritRef = env.GERRIT_REFSPEC ?: null
9def defaultGitRef = env.DEFAULT_GIT_REF ?: null
10def defaultGitUrl = env.DEFAULT_GIT_URL ?: null
Filip Pytlounfcce97c2017-03-07 14:06:07 +010011
Jakub Josef4612c5d2017-03-30 16:04:26 +020012def checkouted = false
Jakub Joseffcb615e2017-04-10 14:34:40 +020013def merged = false
chnydad66d6fa2017-06-22 09:34:43 +020014def systemRefspec = "HEAD"
Vasyl Saienko6c3cd6b2018-06-26 14:02:51 +030015def formulasRevision = 'testing'
azvyagintsev2f10cf52018-09-20 11:30:47 +030016
Jakub Josefa63f9862018-01-11 17:58:38 +010017timeout(time: 12, unit: 'HOURS') {
azvyagintsevb266ad22018-09-11 12:11:11 +030018 node(slaveNode) {
azvyagintsev0c97ffc2018-09-11 11:55:58 +030019 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(',')
azvyagintsev2f10cf52018-09-20 11:30:47 +030054 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 }
azvyagintsev0c97ffc2018-09-11 11:55:58 +030067 }
azvyagintsev2f10cf52018-09-20 11:30:47 +030068 } else {
69 common.warningMsg("Tests for ${testModels} skipped!")
azvyagintsev0c97ffc2018-09-11 11:55:58 +030070 }
71 branches["cookiecutter"] = {
72 build job: "test-mk-cookiecutter-templates", parameters: [
azvyagintsevb266ad22018-09-11 12:11:11 +030073 [$class: 'StringParameterValue', name: 'RECLASS_SYSTEM_URL', value: defaultGitUrl],
74 [$class: 'StringParameterValue', name: 'RECLASS_SYSTEM_GIT_REF', value: systemRefspec],
azvyagintsev0c97ffc2018-09-11 11:55:58 +030075 [$class: 'StringParameterValue', name: 'DISTRIB_REVISION', value: formulasRevision]
76
77 ]
78 }
79 parallel branches
80 } else {
azvyagintsev2f10cf52018-09-20 11:30:47 +030081 error("Cannot checkout gerrit patchset, GERRIT_REFSPEC and DEFAULT_GIT_REF is null")
azvyagintsev0c97ffc2018-09-11 11:55:58 +030082 }
83 }
84 }
85 } catch (Throwable e) {
azvyagintsev0c97ffc2018-09-11 11:55:58 +030086 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 Josefa63f9862018-01-11 17:58:38 +010091 }
Filip Pytlounfcce97c2017-03-07 14:06:07 +010092 }
Filip Pytloun19376a82017-03-07 12:29:00 +010093}