blob: 47dde97efb96c09fd46d7314f064f15abb7fc758 [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"
azvyagintsev2f10cf52018-09-20 11:30:47 +030015
Jakub Josefa63f9862018-01-11 17:58:38 +010016timeout(time: 12, unit: 'HOURS') {
azvyagintsevb266ad22018-09-11 12:11:11 +030017 node(slaveNode) {
azvyagintsev0c97ffc2018-09-11 11:55:58 +030018 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 }
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)
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(',')
azvyagintsev2f10cf52018-09-20 11:30:47 +030053 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],
azvyagintsevb6ca9352018-09-20 13:10:55 +030062 [$class: 'StringParameterValue', name: 'SYSTEM_GIT_REF', value: systemRefspec]
azvyagintsev2f10cf52018-09-20 11:30:47 +030063 ]
64 }
azvyagintsev0c97ffc2018-09-11 11:55:58 +030065 }
azvyagintsev2f10cf52018-09-20 11:30:47 +030066 } else {
67 common.warningMsg("Tests for ${testModels} skipped!")
azvyagintsev0c97ffc2018-09-11 11:55:58 +030068 }
69 branches["cookiecutter"] = {
70 build job: "test-mk-cookiecutter-templates", parameters: [
azvyagintsevb266ad22018-09-11 12:11:11 +030071 [$class: 'StringParameterValue', name: 'RECLASS_SYSTEM_URL', value: defaultGitUrl],
azvyagintsevb6ca9352018-09-20 13:10:55 +030072 [$class: 'StringParameterValue', name: 'RECLASS_SYSTEM_GIT_REF', value: systemRefspec]
azvyagintsev0c97ffc2018-09-11 11:55:58 +030073 ]
74 }
75 parallel branches
76 } else {
azvyagintsev2f10cf52018-09-20 11:30:47 +030077 error("Cannot checkout gerrit patchset, GERRIT_REFSPEC and DEFAULT_GIT_REF is null")
azvyagintsev0c97ffc2018-09-11 11:55:58 +030078 }
79 }
80 }
81 } catch (Throwable e) {
azvyagintsev0c97ffc2018-09-11 11:55:58 +030082 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 Josefa63f9862018-01-11 17:58:38 +010087 }
Filip Pytlounfcce97c2017-03-07 14:06:07 +010088 }
Filip Pytloun19376a82017-03-07 12:29:00 +010089}