blob: 1494aca7eb2809d6b96d9e8fada2bd04bcccbf2a [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
6 */
Jakub Josefc5a223a2017-03-01 14:40:08 +01007def common = new com.mirantis.mk.Common()
8def gerrit = new com.mirantis.mk.Gerrit()
Jakub Joseff64c6392017-05-03 13:18:25 +02009def ruby = new com.mirantis.mk.Ruby()
Jakub Josef83379312017-03-29 18:12:34 +020010
11def gerritRef
12try {
13 gerritRef = GERRIT_REFSPEC
14} catch (MissingPropertyException e) {
15 gerritRef = null
16}
17
18def defaultGitRef, defaultGitUrl
19try {
Martin Polreicha3e30122017-08-22 12:43:55 +020020 defaultGitRef = DEFAULT_GIT_REF
21 defaultGitUrl = DEFAULT_GIT_URL
Jakub Josef83379312017-03-29 18:12:34 +020022} catch (MissingPropertyException e) {
Martin Polreicha3e30122017-08-22 12:43:55 +020023 defaultGitRef = null
24 defaultGitUrl = null
Jakub Josef83379312017-03-29 18:12:34 +020025}
26
Jakub Josefbcd2e902017-06-13 14:40:41 +020027def checkouted = false
Jakub Josef83379312017-03-29 18:12:34 +020028
chnyda3b1d2a62017-06-13 10:08:12 +020029node("python") {
Martin Polreicha3e30122017-08-22 12:43:55 +020030 try {
Jakub Josefc5a223a2017-03-01 14:40:08 +010031 stage("checkout") {
Jakub Josef83379312017-03-29 18:12:34 +020032 if (gerritRef) {
33 // job is triggered by Gerrit
Jakub Josefb2235902017-06-16 12:49:16 +020034 def gerritChange = gerrit.getGerritChange(GERRIT_NAME, GERRIT_HOST, GERRIT_CHANGE_NUMBER, CREDENTIALS_ID, true)
35 // test if gerrit change is already Verified
Martin Polreicha3e30122017-08-22 12:43:55 +020036 if (gerrit.patchsetHasApproval(gerritChange.currentPatchSet, "Verified", "+")) {
Jakub Josef894f1e32017-06-19 16:24:19 +000037 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 +020038 // test WIP contains in commit message
39 } else if (gerritChange.commitMessage.contains("WIP")) {
Jakub Josef894f1e32017-06-19 16:24:19 +000040 common.successMsg("Commit message contains WIP, skipping tests") // do nothing
Martin Polreicha3e30122017-08-22 12:43:55 +020041 } else {
Jakub Josefbcd2e902017-06-13 14:40:41 +020042 // test if change aren't already merged
43 def merged = gerritChange.status == "MERGED"
Martin Polreicha3e30122017-08-22 12:43:55 +020044 if (!merged) {
45 checkouted = gerrit.gerritPatchsetCheckout([
46 credentialsId: CREDENTIALS_ID
Jakub Josefbcd2e902017-06-13 14:40:41 +020047 ])
Martin Polreicha3e30122017-08-22 12:43:55 +020048 } else {
Jakub Josefbcd2e902017-06-13 14:40:41 +020049 common.successMsg("Change ${GERRIT_CHANGE_NUMBER} is already merged, no need to test them")
50 }
Jakub Josef740a7882017-06-01 14:54:01 +020051 }
Martin Polreich4661cd92017-08-29 19:05:10 +020052 defaultGitUrl = "${GERRIT_SCHEME}://${GERRIT_NAME}@${GERRIT_HOST}:${GERRIT_PORT}/${GERRIT_PROJECT}"
53 defaultGitRef = GERRIT_REFSPEC
Martin Polreicha3e30122017-08-22 12:43:55 +020054 } else if (defaultGitRef && defaultGitUrl) {
55 checkouted = gerrit.gerritPatchsetCheckout(defaultGitUrl, defaultGitRef, "HEAD", CREDENTIALS_ID)
Jakub Josefbcd2e902017-06-13 14:40:41 +020056 } else {
Jakub Josef5ce6a362017-03-31 13:41:17 +020057 throw new Exception("Cannot checkout gerrit patchset, GERRIT_REFSPEC and DEFAULT_GIT_REF is null")
Jakub Josef83379312017-03-29 18:12:34 +020058 }
Jakub Josefc5a223a2017-03-01 14:40:08 +010059 }
60 stage("test") {
Martin Polreicha3e30122017-08-22 12:43:55 +020061 if (checkouted) {
Ruslan Kamaldinov310ffc02017-08-08 16:07:42 +040062 sh("make clean")
63 sh("[ $SALT_VERSION != 'latest' ] || export SALT_VERSION=''; make test")
Jakub Josefc5a223a2017-03-01 14:40:08 +010064 }
65 }
Jakub Joseff64c6392017-05-03 13:18:25 +020066 stage("kitchen") {
Martin Polreicha3e30122017-08-22 12:43:55 +020067 if (checkouted) {
Jakub Josefbcd2e902017-06-13 14:40:41 +020068 if (fileExists(".kitchen.yml")) {
69 common.infoMsg(".kitchen.yml found, running kitchen tests")
Jakub Josefbcd2e902017-06-13 14:40:41 +020070 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 != '') {
Martin Polreicha5b119d2017-08-29 16:32:56 +020087 def kitchenTestRuns = [:]
Martin Polreicha3e30122017-08-22 12:43:55 +020088 common.infoMsg("Found " + kitchenEnvs.size() + " environment(s)")
Martin Polreicha3e30122017-08-22 12:43:55 +020089 for (int i = 0; i < kitchenEnvs.size(); i++) {
Martin Polreicha3e30122017-08-22 12:43:55 +020090 def testEnv = kitchenEnvs[i]
91 kitchenTestRuns[testEnv] = {
92 build job: "test-salt-formulas-env", parameters: [
93 [$class: 'StringParameterValue', name: 'CREDENTIALS_ID', value: CREDENTIALS_ID],
94 [$class: 'StringParameterValue', name: 'KITCHEN_ENV', value: testEnv],
Martin Polreich4661cd92017-08-29 19:05:10 +020095 [$class: 'StringParameterValue', name: 'DEFAULT_GIT_REF', value: defaultGitRef],
96 [$class: 'StringParameterValue', name: 'DEFAULT_GIT_URL', value: defaultGitUrl],
Martin Polreicha3e30122017-08-22 12:43:55 +020097 [$class: 'StringParameterValue', name: 'SALT_OPTS', value: SALT_OPTS],
98 [$class: 'StringParameterValue', name: 'SALT_VERSION', value: SALT_VERSION]
99 ]
100 }
Martin Polreicha3e30122017-08-22 12:43:55 +0200101 }
chnyda134ac922017-09-22 13:26:21 +0200102 parallel kitchenTestRuns
Martin Polreicha3e30122017-08-22 12:43:55 +0200103 } else {
104 common.warningMsg(".kitchen.yml file not found, no kitchen tests triggered.")
105 }
Jakub Joseff64c6392017-05-03 13:18:25 +0200106 }
Jakub Joseff64c6392017-05-03 13:18:25 +0200107 }
108 }
Jakub Josefc5a223a2017-03-01 14:40:08 +0100109 } catch (Throwable e) {
Martin Polreicha3e30122017-08-22 12:43:55 +0200110 // If there was an error or exception thrown, the build failed
111 currentBuild.result = "FAILURE"
112 currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message
Martin Polreicha3e30122017-08-22 12:43:55 +0200113 throw e
Jakub Josefc5a223a2017-03-01 14:40:08 +0100114 } finally {
Martin Polreicha3e30122017-08-22 12:43:55 +0200115 if (currentBuild.result == "FAILURE" && fileExists(".kitchen/logs/kitchen.log")) {
116 common.errorMsg("----------------KITCHEN LOG:---------------")
117 println readFile(".kitchen/logs/kitchen.log")
118 }
119 common.sendNotification(currentBuild.result, "", ["slack"])
Jakub Josefc5a223a2017-03-01 14:40:08 +0100120 }
Martin Polreicha3e30122017-08-22 12:43:55 +0200121}