blob: 4422ca648a0c2e857c1188c0f94387f878cd9fff [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
Martin Polreichbe93d362017-08-29 16:09:40 +020019def parallelGroupSize
20try {
21 parallelGroupSize = Integer.valueOf(PARALLEL_GROUP_SIZE)
22} catch (MissingPropertyException e) {
Martin Polreich71a92442017-08-30 12:15:02 +020023 parallelGroupSize = 8
Martin Polreichbe93d362017-08-29 16:09:40 +020024}
25
Jakub Josef83379312017-03-29 18:12:34 +020026def defaultGitRef, defaultGitUrl
27try {
Martin Polreicha3e30122017-08-22 12:43:55 +020028 defaultGitRef = DEFAULT_GIT_REF
29 defaultGitUrl = DEFAULT_GIT_URL
Jakub Josef83379312017-03-29 18:12:34 +020030} catch (MissingPropertyException e) {
Martin Polreicha3e30122017-08-22 12:43:55 +020031 defaultGitRef = null
32 defaultGitUrl = null
Jakub Josef83379312017-03-29 18:12:34 +020033}
34
Jakub Josefbcd2e902017-06-13 14:40:41 +020035def checkouted = false
Jakub Josef83379312017-03-29 18:12:34 +020036
chnyda3b1d2a62017-06-13 10:08:12 +020037node("python") {
Martin Polreicha3e30122017-08-22 12:43:55 +020038 try {
Jakub Josefc5a223a2017-03-01 14:40:08 +010039 stage("checkout") {
Jakub Josef83379312017-03-29 18:12:34 +020040 if (gerritRef) {
41 // job is triggered by Gerrit
Jakub Josefb2235902017-06-16 12:49:16 +020042 def gerritChange = gerrit.getGerritChange(GERRIT_NAME, GERRIT_HOST, GERRIT_CHANGE_NUMBER, CREDENTIALS_ID, true)
43 // test if gerrit change is already Verified
Martin Polreicha3e30122017-08-22 12:43:55 +020044 if (gerrit.patchsetHasApproval(gerritChange.currentPatchSet, "Verified", "+")) {
Jakub Josef894f1e32017-06-19 16:24:19 +000045 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 +020046 // test WIP contains in commit message
47 } else if (gerritChange.commitMessage.contains("WIP")) {
Jakub Josef894f1e32017-06-19 16:24:19 +000048 common.successMsg("Commit message contains WIP, skipping tests") // do nothing
Martin Polreicha3e30122017-08-22 12:43:55 +020049 } else {
Jakub Josefbcd2e902017-06-13 14:40:41 +020050 // test if change aren't already merged
51 def merged = gerritChange.status == "MERGED"
Martin Polreicha3e30122017-08-22 12:43:55 +020052 if (!merged) {
53 checkouted = gerrit.gerritPatchsetCheckout([
54 credentialsId: CREDENTIALS_ID
Jakub Josefbcd2e902017-06-13 14:40:41 +020055 ])
Martin Polreicha3e30122017-08-22 12:43:55 +020056 } else {
Jakub Josefbcd2e902017-06-13 14:40:41 +020057 common.successMsg("Change ${GERRIT_CHANGE_NUMBER} is already merged, no need to test them")
58 }
Jakub Josef740a7882017-06-01 14:54:01 +020059 }
Martin Polreich4661cd92017-08-29 19:05:10 +020060 defaultGitUrl = "${GERRIT_SCHEME}://${GERRIT_NAME}@${GERRIT_HOST}:${GERRIT_PORT}/${GERRIT_PROJECT}"
61 defaultGitRef = GERRIT_REFSPEC
Martin Polreicha3e30122017-08-22 12:43:55 +020062 } else if (defaultGitRef && defaultGitUrl) {
63 checkouted = gerrit.gerritPatchsetCheckout(defaultGitUrl, defaultGitRef, "HEAD", CREDENTIALS_ID)
Jakub Josefbcd2e902017-06-13 14:40:41 +020064 } else {
Jakub Josef5ce6a362017-03-31 13:41:17 +020065 throw new Exception("Cannot checkout gerrit patchset, GERRIT_REFSPEC and DEFAULT_GIT_REF is null")
Jakub Josef83379312017-03-29 18:12:34 +020066 }
Jakub Josefc5a223a2017-03-01 14:40:08 +010067 }
68 stage("test") {
Martin Polreicha3e30122017-08-22 12:43:55 +020069 if (checkouted) {
Ruslan Kamaldinov310ffc02017-08-08 16:07:42 +040070 sh("make clean")
71 sh("[ $SALT_VERSION != 'latest' ] || export SALT_VERSION=''; make test")
Jakub Josefc5a223a2017-03-01 14:40:08 +010072 }
73 }
Jakub Joseff64c6392017-05-03 13:18:25 +020074 stage("kitchen") {
Martin Polreicha3e30122017-08-22 12:43:55 +020075 if (checkouted) {
Jakub Josefbcd2e902017-06-13 14:40:41 +020076 if (fileExists(".kitchen.yml")) {
77 common.infoMsg(".kitchen.yml found, running kitchen tests")
Jakub Josefbcd2e902017-06-13 14:40:41 +020078 def kitchenEnvs = []
Martin Polreich9b5f5ab2017-07-12 13:06:14 +020079 def filteredEnvs = []
Martin Polreicha3e30122017-08-22 12:43:55 +020080 if (fileExists(".travis.yml")) {
81 common.infoMsg(".travis.yml file found.")
Jakub Josefbcd2e902017-06-13 14:40:41 +020082 def kitchenConfigYML = readYaml(file: ".travis.yml")
Martin Polreicha3e30122017-08-22 12:43:55 +020083 if (kitchenConfigYML.containsKey("env")) {
84 kitchenEnvs = kitchenConfigYML["env"]
Ruslan Kamaldinov310ffc02017-08-08 16:07:42 +040085 }
86 } else {
Martin Polreicha3e30122017-08-22 12:43:55 +020087 common.warningMsg(".travis.yml file not found, suites must be passed via CUSTOM_KITCHEN_ENVS parameter.")
Jakub Josefbcd2e902017-06-13 14:40:41 +020088 }
Martin Polreicha3e30122017-08-22 12:43:55 +020089 common.infoMsg("Running kitchen testing in parallel mode")
90 if (CUSTOM_KITCHEN_ENVS != null && CUSTOM_KITCHEN_ENVS != '') {
91 kitchenEnvs = CUSTOM_KITCHEN_ENVS.tokenize('\n')
92 common.infoMsg("CUSTOM_KITCHEN_ENVS not empty. Running with custom enviroments: ${kitchenEnvs}")
93 }
94 if (kitchenEnvs != null && kitchenEnvs != '') {
Martin Polreicha5b119d2017-08-29 16:32:56 +020095 def acc = 0
96 def kitchenTestRuns = [:]
Martin Polreicha3e30122017-08-22 12:43:55 +020097 common.infoMsg("Found " + kitchenEnvs.size() + " environment(s)")
Martin Polreicha3e30122017-08-22 12:43:55 +020098 for (int i = 0; i < kitchenEnvs.size(); i++) {
99 if (acc >= parallelGroupSize) {
100 parallel kitchenTestRuns
Martin Polreicha5b119d2017-08-29 16:32:56 +0200101 kitchenTestRuns = [:]
Martin Polreicha3e30122017-08-22 12:43:55 +0200102 acc = 0
103 }
104 def testEnv = kitchenEnvs[i]
105 kitchenTestRuns[testEnv] = {
106 build job: "test-salt-formulas-env", parameters: [
107 [$class: 'StringParameterValue', name: 'CREDENTIALS_ID', value: CREDENTIALS_ID],
108 [$class: 'StringParameterValue', name: 'KITCHEN_ENV', value: testEnv],
Martin Polreich4661cd92017-08-29 19:05:10 +0200109 [$class: 'StringParameterValue', name: 'DEFAULT_GIT_REF', value: defaultGitRef],
110 [$class: 'StringParameterValue', name: 'DEFAULT_GIT_URL', value: defaultGitUrl],
Martin Polreicha3e30122017-08-22 12:43:55 +0200111 [$class: 'StringParameterValue', name: 'SALT_OPTS', value: SALT_OPTS],
112 [$class: 'StringParameterValue', name: 'SALT_VERSION', value: SALT_VERSION]
113 ]
114 }
115 acc++;
116 }
117 if (acc != 0) {
118 parallel kitchenTestRuns
119 }
120 } else {
121 common.warningMsg(".kitchen.yml file not found, no kitchen tests triggered.")
122 }
Jakub Joseff64c6392017-05-03 13:18:25 +0200123 }
Jakub Joseff64c6392017-05-03 13:18:25 +0200124 }
125 }
Jakub Josefc5a223a2017-03-01 14:40:08 +0100126 } catch (Throwable e) {
Martin Polreicha3e30122017-08-22 12:43:55 +0200127 // If there was an error or exception thrown, the build failed
128 currentBuild.result = "FAILURE"
129 currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message
Martin Polreicha3e30122017-08-22 12:43:55 +0200130 throw e
Jakub Josefc5a223a2017-03-01 14:40:08 +0100131 } finally {
Martin Polreicha3e30122017-08-22 12:43:55 +0200132 if (currentBuild.result == "FAILURE" && fileExists(".kitchen/logs/kitchen.log")) {
133 common.errorMsg("----------------KITCHEN LOG:---------------")
134 println readFile(".kitchen/logs/kitchen.log")
135 }
136 common.sendNotification(currentBuild.result, "", ["slack"])
Jakub Josefc5a223a2017-03-01 14:40:08 +0100137 }
Martin Polreicha3e30122017-08-22 12:43:55 +0200138}