blob: afd2857a434a3bf2a6053b23960ea5afdb9976f0 [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
5slaveNode = env.SLAVE_NODE ?: 'python&&docker'
6
Filip Pytlounfcce97c2017-03-07 14:06:07 +01007def gerritCredentials
8try {
9 gerritCredentials = CREDENTIALS_ID
10} catch (MissingPropertyException e) {
11 gerritCredentials = "gerrit"
12}
13
Jakub Josef4612c5d2017-03-30 16:04:26 +020014def gerritRef
15try {
azvyagintsev0c97ffc2018-09-11 11:55:58 +030016 gerritRef = GERRIT_REFSPEC
Jakub Josef4612c5d2017-03-30 16:04:26 +020017} catch (MissingPropertyException e) {
azvyagintsev0c97ffc2018-09-11 11:55:58 +030018 gerritRef = null
Jakub Josef4612c5d2017-03-30 16:04:26 +020019}
20
21def defaultGitRef, defaultGitUrl
22try {
23 defaultGitRef = DEFAULT_GIT_REF
24 defaultGitUrl = DEFAULT_GIT_URL
25} catch (MissingPropertyException e) {
26 defaultGitRef = null
27 defaultGitUrl = null
28}
29def checkouted = false
Jakub Joseffcb615e2017-04-10 14:34:40 +020030def merged = false
chnydad66d6fa2017-06-22 09:34:43 +020031def systemRefspec = "HEAD"
Vasyl Saienko6c3cd6b2018-06-26 14:02:51 +030032def formulasRevision = 'testing'
Jakub Josefa63f9862018-01-11 17:58:38 +010033timeout(time: 12, unit: 'HOURS') {
azvyagintsevb266ad22018-09-11 12:11:11 +030034 node(slaveNode) {
azvyagintsev0c97ffc2018-09-11 11:55:58 +030035 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: [
azvyagintsevb266ad22018-09-11 12:11:11 +030085 [$class: 'StringParameterValue', name: 'RECLASS_SYSTEM_URL', value: defaultGitUrl],
86 [$class: 'StringParameterValue', name: 'RECLASS_SYSTEM_GIT_REF', value: systemRefspec],
azvyagintsev0c97ffc2018-09-11 11:55:58 +030087 [$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 Josefa63f9862018-01-11 17:58:38 +0100104 }
Filip Pytlounfcce97c2017-03-07 14:06:07 +0100105 }
Filip Pytloun19376a82017-03-07 12:29:00 +0100106}