Jakub Josef | 8337931 | 2017-03-29 18:12:34 +0200 | [diff] [blame] | 1 | /** |
| 2 | * Test salt formulas pipeline |
| 3 | * DEFAULT_GIT_REF |
| 4 | * DEFAULT_GIT_URL |
| 5 | * CREDENTIALS_ID |
| 6 | */ |
Jakub Josef | c5a223a | 2017-03-01 14:40:08 +0100 | [diff] [blame] | 7 | def common = new com.mirantis.mk.Common() |
| 8 | def gerrit = new com.mirantis.mk.Gerrit() |
Jakub Josef | f64c639 | 2017-05-03 13:18:25 +0200 | [diff] [blame] | 9 | def ruby = new com.mirantis.mk.Ruby() |
Jakub Josef | 8337931 | 2017-03-29 18:12:34 +0200 | [diff] [blame] | 10 | |
| 11 | def gerritRef |
| 12 | try { |
| 13 | gerritRef = GERRIT_REFSPEC |
| 14 | } catch (MissingPropertyException e) { |
| 15 | gerritRef = null |
| 16 | } |
| 17 | |
| 18 | def defaultGitRef, defaultGitUrl |
| 19 | try { |
Martin Polreich | a3e3012 | 2017-08-22 12:43:55 +0200 | [diff] [blame] | 20 | defaultGitRef = DEFAULT_GIT_REF |
| 21 | defaultGitUrl = DEFAULT_GIT_URL |
Jakub Josef | 8337931 | 2017-03-29 18:12:34 +0200 | [diff] [blame] | 22 | } catch (MissingPropertyException e) { |
Martin Polreich | a3e3012 | 2017-08-22 12:43:55 +0200 | [diff] [blame] | 23 | defaultGitRef = null |
| 24 | defaultGitUrl = null |
Jakub Josef | 8337931 | 2017-03-29 18:12:34 +0200 | [diff] [blame] | 25 | } |
| 26 | |
Jakub Josef | bcd2e90 | 2017-06-13 14:40:41 +0200 | [diff] [blame] | 27 | def checkouted = false |
Jakub Josef | 8337931 | 2017-03-29 18:12:34 +0200 | [diff] [blame] | 28 | |
chnyda | 3b1d2a6 | 2017-06-13 10:08:12 +0200 | [diff] [blame] | 29 | node("python") { |
Martin Polreich | a3e3012 | 2017-08-22 12:43:55 +0200 | [diff] [blame] | 30 | try { |
Jakub Josef | c5a223a | 2017-03-01 14:40:08 +0100 | [diff] [blame] | 31 | stage("checkout") { |
Jakub Josef | 8337931 | 2017-03-29 18:12:34 +0200 | [diff] [blame] | 32 | if (gerritRef) { |
| 33 | // job is triggered by Gerrit |
Jakub Josef | b223590 | 2017-06-16 12:49:16 +0200 | [diff] [blame] | 34 | def gerritChange = gerrit.getGerritChange(GERRIT_NAME, GERRIT_HOST, GERRIT_CHANGE_NUMBER, CREDENTIALS_ID, true) |
| 35 | // test if gerrit change is already Verified |
Martin Polreich | a3e3012 | 2017-08-22 12:43:55 +0200 | [diff] [blame] | 36 | if (gerrit.patchsetHasApproval(gerritChange.currentPatchSet, "Verified", "+")) { |
Jakub Josef | 894f1e3 | 2017-06-19 16:24:19 +0000 | [diff] [blame] | 37 | common.successMsg("Gerrit change ${GERRIT_CHANGE_NUMBER} patchset ${GERRIT_PATCHSET_NUMBER} already has Verified, skipping tests") // do nothing |
Martin Polreich | a3e3012 | 2017-08-22 12:43:55 +0200 | [diff] [blame] | 38 | // test WIP contains in commit message |
| 39 | } else if (gerritChange.commitMessage.contains("WIP")) { |
Jakub Josef | 894f1e3 | 2017-06-19 16:24:19 +0000 | [diff] [blame] | 40 | common.successMsg("Commit message contains WIP, skipping tests") // do nothing |
Martin Polreich | a3e3012 | 2017-08-22 12:43:55 +0200 | [diff] [blame] | 41 | } else { |
Jakub Josef | bcd2e90 | 2017-06-13 14:40:41 +0200 | [diff] [blame] | 42 | // test if change aren't already merged |
| 43 | def merged = gerritChange.status == "MERGED" |
Martin Polreich | a3e3012 | 2017-08-22 12:43:55 +0200 | [diff] [blame] | 44 | if (!merged) { |
| 45 | checkouted = gerrit.gerritPatchsetCheckout([ |
| 46 | credentialsId: CREDENTIALS_ID |
Jakub Josef | bcd2e90 | 2017-06-13 14:40:41 +0200 | [diff] [blame] | 47 | ]) |
Martin Polreich | a3e3012 | 2017-08-22 12:43:55 +0200 | [diff] [blame] | 48 | } else { |
Jakub Josef | bcd2e90 | 2017-06-13 14:40:41 +0200 | [diff] [blame] | 49 | common.successMsg("Change ${GERRIT_CHANGE_NUMBER} is already merged, no need to test them") |
| 50 | } |
Jakub Josef | 740a788 | 2017-06-01 14:54:01 +0200 | [diff] [blame] | 51 | } |
Martin Polreich | 4661cd9 | 2017-08-29 19:05:10 +0200 | [diff] [blame] | 52 | defaultGitUrl = "${GERRIT_SCHEME}://${GERRIT_NAME}@${GERRIT_HOST}:${GERRIT_PORT}/${GERRIT_PROJECT}" |
| 53 | defaultGitRef = GERRIT_REFSPEC |
Martin Polreich | a3e3012 | 2017-08-22 12:43:55 +0200 | [diff] [blame] | 54 | } else if (defaultGitRef && defaultGitUrl) { |
| 55 | checkouted = gerrit.gerritPatchsetCheckout(defaultGitUrl, defaultGitRef, "HEAD", CREDENTIALS_ID) |
Jakub Josef | bcd2e90 | 2017-06-13 14:40:41 +0200 | [diff] [blame] | 56 | } else { |
Jakub Josef | 5ce6a36 | 2017-03-31 13:41:17 +0200 | [diff] [blame] | 57 | throw new Exception("Cannot checkout gerrit patchset, GERRIT_REFSPEC and DEFAULT_GIT_REF is null") |
Jakub Josef | 8337931 | 2017-03-29 18:12:34 +0200 | [diff] [blame] | 58 | } |
Jakub Josef | c5a223a | 2017-03-01 14:40:08 +0100 | [diff] [blame] | 59 | } |
| 60 | stage("test") { |
Martin Polreich | a3e3012 | 2017-08-22 12:43:55 +0200 | [diff] [blame] | 61 | if (checkouted) { |
Ruslan Kamaldinov | 310ffc0 | 2017-08-08 16:07:42 +0400 | [diff] [blame] | 62 | sh("make clean") |
| 63 | sh("[ $SALT_VERSION != 'latest' ] || export SALT_VERSION=''; make test") |
Jakub Josef | c5a223a | 2017-03-01 14:40:08 +0100 | [diff] [blame] | 64 | } |
| 65 | } |
Jakub Josef | f64c639 | 2017-05-03 13:18:25 +0200 | [diff] [blame] | 66 | stage("kitchen") { |
Martin Polreich | a3e3012 | 2017-08-22 12:43:55 +0200 | [diff] [blame] | 67 | if (checkouted) { |
Jakub Josef | bcd2e90 | 2017-06-13 14:40:41 +0200 | [diff] [blame] | 68 | if (fileExists(".kitchen.yml")) { |
| 69 | common.infoMsg(".kitchen.yml found, running kitchen tests") |
Jakub Josef | bcd2e90 | 2017-06-13 14:40:41 +0200 | [diff] [blame] | 70 | def kitchenEnvs = [] |
Martin Polreich | 9b5f5ab | 2017-07-12 13:06:14 +0200 | [diff] [blame] | 71 | def filteredEnvs = [] |
Martin Polreich | a3e3012 | 2017-08-22 12:43:55 +0200 | [diff] [blame] | 72 | if (fileExists(".travis.yml")) { |
| 73 | common.infoMsg(".travis.yml file found.") |
Jakub Josef | bcd2e90 | 2017-06-13 14:40:41 +0200 | [diff] [blame] | 74 | def kitchenConfigYML = readYaml(file: ".travis.yml") |
Martin Polreich | a3e3012 | 2017-08-22 12:43:55 +0200 | [diff] [blame] | 75 | if (kitchenConfigYML.containsKey("env")) { |
| 76 | kitchenEnvs = kitchenConfigYML["env"] |
Ruslan Kamaldinov | 310ffc0 | 2017-08-08 16:07:42 +0400 | [diff] [blame] | 77 | } |
| 78 | } else { |
Martin Polreich | a3e3012 | 2017-08-22 12:43:55 +0200 | [diff] [blame] | 79 | common.warningMsg(".travis.yml file not found, suites must be passed via CUSTOM_KITCHEN_ENVS parameter.") |
Jakub Josef | bcd2e90 | 2017-06-13 14:40:41 +0200 | [diff] [blame] | 80 | } |
Martin Polreich | a3e3012 | 2017-08-22 12:43:55 +0200 | [diff] [blame] | 81 | 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 Polreich | a5b119d | 2017-08-29 16:32:56 +0200 | [diff] [blame] | 87 | def kitchenTestRuns = [:] |
Martin Polreich | a3e3012 | 2017-08-22 12:43:55 +0200 | [diff] [blame] | 88 | common.infoMsg("Found " + kitchenEnvs.size() + " environment(s)") |
Martin Polreich | a3e3012 | 2017-08-22 12:43:55 +0200 | [diff] [blame] | 89 | for (int i = 0; i < kitchenEnvs.size(); i++) { |
Martin Polreich | a3e3012 | 2017-08-22 12:43:55 +0200 | [diff] [blame] | 90 | 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 Polreich | 4661cd9 | 2017-08-29 19:05:10 +0200 | [diff] [blame] | 95 | [$class: 'StringParameterValue', name: 'DEFAULT_GIT_REF', value: defaultGitRef], |
| 96 | [$class: 'StringParameterValue', name: 'DEFAULT_GIT_URL', value: defaultGitUrl], |
Martin Polreich | a3e3012 | 2017-08-22 12:43:55 +0200 | [diff] [blame] | 97 | [$class: 'StringParameterValue', name: 'SALT_OPTS', value: SALT_OPTS], |
| 98 | [$class: 'StringParameterValue', name: 'SALT_VERSION', value: SALT_VERSION] |
| 99 | ] |
| 100 | } |
Martin Polreich | a3e3012 | 2017-08-22 12:43:55 +0200 | [diff] [blame] | 101 | } |
chnyda | 134ac92 | 2017-09-22 13:26:21 +0200 | [diff] [blame] | 102 | parallel kitchenTestRuns |
Martin Polreich | a3e3012 | 2017-08-22 12:43:55 +0200 | [diff] [blame] | 103 | } else { |
| 104 | common.warningMsg(".kitchen.yml file not found, no kitchen tests triggered.") |
| 105 | } |
Jakub Josef | f64c639 | 2017-05-03 13:18:25 +0200 | [diff] [blame] | 106 | } |
Jakub Josef | f64c639 | 2017-05-03 13:18:25 +0200 | [diff] [blame] | 107 | } |
| 108 | } |
Jakub Josef | c5a223a | 2017-03-01 14:40:08 +0100 | [diff] [blame] | 109 | } catch (Throwable e) { |
Martin Polreich | a3e3012 | 2017-08-22 12:43:55 +0200 | [diff] [blame] | 110 | // 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 Polreich | a3e3012 | 2017-08-22 12:43:55 +0200 | [diff] [blame] | 113 | throw e |
Jakub Josef | c5a223a | 2017-03-01 14:40:08 +0100 | [diff] [blame] | 114 | } finally { |
Martin Polreich | a3e3012 | 2017-08-22 12:43:55 +0200 | [diff] [blame] | 115 | 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 Josef | c5a223a | 2017-03-01 14:40:08 +0100 | [diff] [blame] | 120 | } |
Martin Polreich | a3e3012 | 2017-08-22 12:43:55 +0200 | [diff] [blame] | 121 | } |