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