blob: c36ea179df03a3856aa77454d748595e5ec19990 [file] [log] [blame]
Jakub Josef83379312017-03-29 18:12:34 +02001/**
2 * Test salt formulas pipeline
3 * DEFAULT_GIT_REF
4 * DEFAULT_GIT_URL
5 * CREDENTIALS_ID
Jakub Josef0bbbd802017-05-22 20:28:44 +02006 * KITCHEN_TESTS_PARALLEL
Jakub Josef83379312017-03-29 18:12:34 +02007 */
Jakub Josefc5a223a2017-03-01 14:40:08 +01008def common = new com.mirantis.mk.Common()
9def gerrit = new com.mirantis.mk.Gerrit()
Jakub Joseff64c6392017-05-03 13:18:25 +020010def ruby = new com.mirantis.mk.Ruby()
Jakub Josef83379312017-03-29 18:12:34 +020011
12def gerritRef
13try {
14 gerritRef = GERRIT_REFSPEC
15} catch (MissingPropertyException e) {
16 gerritRef = null
17}
18
19def defaultGitRef, defaultGitUrl
20try {
Martin Polreicha3e30122017-08-22 12:43:55 +020021 defaultGitRef = DEFAULT_GIT_REF
22 defaultGitUrl = DEFAULT_GIT_URL
Jakub Josef83379312017-03-29 18:12:34 +020023} catch (MissingPropertyException e) {
Martin Polreicha3e30122017-08-22 12:43:55 +020024 defaultGitRef = null
25 defaultGitUrl = null
Jakub Josef83379312017-03-29 18:12:34 +020026}
27
Jakub Josefbcd2e902017-06-13 14:40:41 +020028def checkouted = false
Jakub Josef83379312017-03-29 18:12:34 +020029
chnyda3b1d2a62017-06-13 10:08:12 +020030node("python") {
Martin Polreicha3e30122017-08-22 12:43:55 +020031 try {
Jakub Josefc5a223a2017-03-01 14:40:08 +010032 stage("checkout") {
Jakub Josef83379312017-03-29 18:12:34 +020033 if (gerritRef) {
34 // job is triggered by Gerrit
Jakub Josefb2235902017-06-16 12:49:16 +020035 def gerritChange = gerrit.getGerritChange(GERRIT_NAME, GERRIT_HOST, GERRIT_CHANGE_NUMBER, CREDENTIALS_ID, true)
36 // test if gerrit change is already Verified
Martin Polreicha3e30122017-08-22 12:43:55 +020037 if (gerrit.patchsetHasApproval(gerritChange.currentPatchSet, "Verified", "+")) {
Jakub Josef894f1e32017-06-19 16:24:19 +000038 common.successMsg("Gerrit change ${GERRIT_CHANGE_NUMBER} patchset ${GERRIT_PATCHSET_NUMBER} already has Verified, skipping tests") // do nothing
Martin Polreicha3e30122017-08-22 12:43:55 +020039 // test WIP contains in commit message
40 } else if (gerritChange.commitMessage.contains("WIP")) {
Jakub Josef894f1e32017-06-19 16:24:19 +000041 common.successMsg("Commit message contains WIP, skipping tests") // do nothing
Martin Polreicha3e30122017-08-22 12:43:55 +020042 } else {
Jakub Josefbcd2e902017-06-13 14:40:41 +020043 // test if change aren't already merged
44 def merged = gerritChange.status == "MERGED"
Martin Polreicha3e30122017-08-22 12:43:55 +020045 if (!merged) {
46 checkouted = gerrit.gerritPatchsetCheckout([
47 credentialsId: CREDENTIALS_ID
Jakub Josefbcd2e902017-06-13 14:40:41 +020048 ])
Martin Polreicha3e30122017-08-22 12:43:55 +020049 } else {
Jakub Josefbcd2e902017-06-13 14:40:41 +020050 common.successMsg("Change ${GERRIT_CHANGE_NUMBER} is already merged, no need to test them")
51 }
Jakub Josef740a7882017-06-01 14:54:01 +020052 }
Martin Polreicha3e30122017-08-22 12:43:55 +020053 } else if (defaultGitRef && defaultGitUrl) {
54 checkouted = gerrit.gerritPatchsetCheckout(defaultGitUrl, defaultGitRef, "HEAD", CREDENTIALS_ID)
Jakub Josefbcd2e902017-06-13 14:40:41 +020055 } else {
Jakub Josef5ce6a362017-03-31 13:41:17 +020056 throw new Exception("Cannot checkout gerrit patchset, GERRIT_REFSPEC and DEFAULT_GIT_REF is null")
Jakub Josef83379312017-03-29 18:12:34 +020057 }
Jakub Josefc5a223a2017-03-01 14:40:08 +010058 }
59 stage("test") {
Martin Polreicha3e30122017-08-22 12:43:55 +020060 if (checkouted) {
Ruslan Kamaldinov310ffc02017-08-08 16:07:42 +040061 sh("make clean")
62 sh("[ $SALT_VERSION != 'latest' ] || export SALT_VERSION=''; make test")
Jakub Josefc5a223a2017-03-01 14:40:08 +010063 }
64 }
Jakub Joseff64c6392017-05-03 13:18:25 +020065 stage("kitchen") {
Martin Polreicha3e30122017-08-22 12:43:55 +020066 if (checkouted) {
Jakub Josefbcd2e902017-06-13 14:40:41 +020067 if (fileExists(".kitchen.yml")) {
68 common.infoMsg(".kitchen.yml found, running kitchen tests")
69 ruby.ensureRubyEnv()
70 def kitchenEnvs = []
Martin Polreich9b5f5ab2017-07-12 13:06:14 +020071 def filteredEnvs = []
Martin Polreicha3e30122017-08-22 12:43:55 +020072 if (fileExists(".travis.yml")) {
73 common.infoMsg(".travis.yml file found.")
Jakub Josefbcd2e902017-06-13 14:40:41 +020074 def kitchenConfigYML = readYaml(file: ".travis.yml")
Martin Polreicha3e30122017-08-22 12:43:55 +020075 if (kitchenConfigYML.containsKey("env")) {
76 kitchenEnvs = kitchenConfigYML["env"]
Ruslan Kamaldinov310ffc02017-08-08 16:07:42 +040077 }
78 } else {
Martin Polreicha3e30122017-08-22 12:43:55 +020079 common.warningMsg(".travis.yml file not found, suites must be passed via CUSTOM_KITCHEN_ENVS parameter.")
Jakub Josefbcd2e902017-06-13 14:40:41 +020080 }
Martin Polreicha3e30122017-08-22 12:43:55 +020081 common.infoMsg("Running kitchen testing in parallel mode")
82 if (CUSTOM_KITCHEN_ENVS != null && CUSTOM_KITCHEN_ENVS != '') {
83 kitchenEnvs = CUSTOM_KITCHEN_ENVS.tokenize('\n')
84 common.infoMsg("CUSTOM_KITCHEN_ENVS not empty. Running with custom enviroments: ${kitchenEnvs}")
85 }
86 if (kitchenEnvs != null && kitchenEnvs != '') {
87 common.infoMsg("Found " + kitchenEnvs.size() + " environment(s)")
88 print(kitchenEnvs)
89 for (int i = 0; i < kitchenEnvs.size(); i++) {
90 if (acc >= parallelGroupSize) {
91 parallel kitchenTestRuns
92 kitchenTestRuns = [: ]
93 acc = 0
94 }
95 def testEnv = kitchenEnvs[i]
96 kitchenTestRuns[testEnv] = {
97 build job: "test-salt-formulas-env", parameters: [
98 [$class: 'StringParameterValue', name: 'CREDENTIALS_ID', value: CREDENTIALS_ID],
99 [$class: 'StringParameterValue', name: 'KITCHEN_ENV', value: testEnv],
100 [$class: 'StringParameterValue', name: 'DEFAULT_GIT_REF', value: DEFAULT_GIT_REF],
101 [$class: 'StringParameterValue', name: 'DEFAULT_GIT_URL', value: DEFAULT_GIT_URL],
102 [$class: 'StringParameterValue', name: 'SALT_OPTS', value: SALT_OPTS],
103 [$class: 'StringParameterValue', name: 'SALT_VERSION', value: SALT_VERSION]
104 ]
105 }
106 acc++;
107 }
108 if (acc != 0) {
109 parallel kitchenTestRuns
110 }
111 } else {
112 common.warningMsg(".kitchen.yml file not found, no kitchen tests triggered.")
113 }
Jakub Joseff64c6392017-05-03 13:18:25 +0200114 }
Jakub Joseff64c6392017-05-03 13:18:25 +0200115 }
116 }
Jakub Josefc5a223a2017-03-01 14:40:08 +0100117 } catch (Throwable e) {
Martin Polreicha3e30122017-08-22 12:43:55 +0200118 // If there was an error or exception thrown, the build failed
119 currentBuild.result = "FAILURE"
120 currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message
121 ruby.runKitchenCommand("destroy")
122 throw e
Jakub Josefc5a223a2017-03-01 14:40:08 +0100123 } finally {
Martin Polreicha3e30122017-08-22 12:43:55 +0200124 if (currentBuild.result == "FAILURE" && fileExists(".kitchen/logs/kitchen.log")) {
125 common.errorMsg("----------------KITCHEN LOG:---------------")
126 println readFile(".kitchen/logs/kitchen.log")
127 }
128 common.sendNotification(currentBuild.result, "", ["slack"])
Jakub Josefc5a223a2017-03-01 14:40:08 +0100129 }
Martin Polreicha3e30122017-08-22 12:43:55 +0200130}