Martin Polreich | a3e3012 | 2017-08-22 12:43:55 +0200 | [diff] [blame] | 1 | /** |
| 2 | * Test salt formulas pipeline |
| 3 | * DEFAULT_GIT_REF |
| 4 | * DEFAULT_GIT_URL |
| 5 | * CREDENTIALS_ID |
| 6 | */ |
| 7 | def common = new com.mirantis.mk.Common() |
| 8 | def ruby = new com.mirantis.mk.Ruby() |
Martin Polreich | 9a1d16b | 2017-08-29 17:16:12 +0200 | [diff] [blame] | 9 | def gerrit = new com.mirantis.mk.Gerrit() |
Martin Polreich | a3e3012 | 2017-08-22 12:43:55 +0200 | [diff] [blame] | 10 | |
| 11 | def defaultGitRef, defaultGitUrl |
| 12 | try { |
| 13 | defaultGitRef = DEFAULT_GIT_REF |
| 14 | defaultGitUrl = DEFAULT_GIT_URL |
| 15 | } catch (MissingPropertyException e) { |
| 16 | defaultGitRef = null |
| 17 | defaultGitUrl = null |
| 18 | } |
| 19 | |
| 20 | def checkouted = false |
| 21 | |
chnyda | 03f3ad4 | 2017-09-19 14:41:07 +0200 | [diff] [blame] | 22 | throttle(['test-formula']) { |
Jakub Josef | db3ddd8 | 2018-01-23 13:30:47 +0100 | [diff] [blame] | 23 | timeout(time: 1, unit: 'HOURS') { |
Jakub Josef | 22815b0 | 2018-01-30 16:05:26 +0100 | [diff] [blame] | 24 | node("python&&docker") { |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 25 | try { |
| 26 | stage("checkout") { |
| 27 | if (defaultGitRef && defaultGitUrl) { |
| 28 | checkouted = gerrit.gerritPatchsetCheckout(defaultGitUrl, defaultGitRef, "HEAD", CREDENTIALS_ID) |
chnyda | 03f3ad4 | 2017-09-19 14:41:07 +0200 | [diff] [blame] | 29 | } else { |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 30 | throw new Exception("Cannot checkout gerrit patchset, DEFAULT_GIT_REF is null") |
chnyda | 03f3ad4 | 2017-09-19 14:41:07 +0200 | [diff] [blame] | 31 | } |
| 32 | } |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 33 | stage("cleanup") { |
| 34 | if (checkouted) { |
| 35 | sh("make clean") |
| 36 | } |
| 37 | } |
| 38 | stage("kitchen") { |
| 39 | if (checkouted) { |
| 40 | if (fileExists(".kitchen.yml")) { |
| 41 | common.infoMsg(".kitchen.yml found, running kitchen tests") |
| 42 | ruby.ensureRubyEnv() |
| 43 | if (fileExists(".travis.yml")) { |
| 44 | common.infoMsg(".travis.yml found, running custom kitchen init") |
| 45 | def kitchenConfigYML = readYaml(file: ".travis.yml") |
| 46 | def kitchenInit = kitchenConfigYML["install"] |
| 47 | def kitchenInstalled = false |
| 48 | if (kitchenInit && !kitchenInit.isEmpty()) { |
| 49 | for (int i = 0; i < kitchenInit.size(); i++) { |
| 50 | if (kitchenInit[i].trim().startsWith("test -e Gemfile")) { //found Gemfile config |
| 51 | common.infoMsg("Custom Gemfile configuration found, using them") |
| 52 | ruby.installKitchen(kitchenInit[i].trim()) |
| 53 | kitchenInstalled = true |
| 54 | } |
| 55 | } |
| 56 | } |
| 57 | if (!kitchenInstalled) { |
| 58 | ruby.installKitchen() |
| 59 | } |
| 60 | } else { |
| 61 | common.infoMsg(".travis.yml not found, running default kitchen init") |
| 62 | ruby.installKitchen() |
| 63 | } |
| 64 | common.infoMsg("Running part of kitchen test") |
| 65 | if (KITCHEN_ENV != null && !KITCHEN_ENV.isEmpty() && KITCHEN_ENV != "") { |
| 66 | def cleanEnv = KITCHEN_ENV.replaceAll("\\s?SUITE=[^\\s]*", "") |
| 67 | sh("find . -type f -exec sed -i 's/apt.mirantis.com/apt.mirantis.net:8085/g' {} \\;") |
| 68 | sh("find . -type f -exec sed -i 's/apt-mk.mirantis.com/apt.mirantis.net:8085/g' {} \\;") |
| 69 | def suite = ruby.getSuiteName(KITCHEN_ENV) |
| 70 | if (suite && suite != "") { |
| 71 | common.infoMsg("Running kitchen test with environment:" + KITCHEN_ENV.trim()) |
| 72 | ruby.runKitchenTests(cleanEnv, suite) |
| 73 | } else { |
| 74 | common.warningMsg("No SUITE was found. Running with all suites.") |
| 75 | ruby.runKitchenTests(cleanEnv, "") |
| 76 | } |
| 77 | } else { |
| 78 | throw new Exception("KITCHEN_ENV parameter is empty or invalid. This may indicate wrong env settings of initial test job or .travis.yml file.") |
| 79 | } |
| 80 | } else { |
| 81 | throw new Exception(".kitchen.yml file not found, no kitchen tests triggered.") |
| 82 | } |
| 83 | } |
| 84 | } |
| 85 | } catch (Throwable e) { |
| 86 | // If there was an error or exception thrown, the build failed |
| 87 | currentBuild.result = "FAILURE" |
| 88 | ruby.runKitchenCommand("destroy") |
| 89 | throw e |
| 90 | } finally { |
| 91 | if (currentBuild.result == "FAILURE" && fileExists(".kitchen/logs/kitchen.log")) { |
| 92 | common.errorMsg("----------------KITCHEN LOG:---------------") |
| 93 | println readFile(".kitchen/logs/kitchen.log") |
| 94 | } |
chnyda | 03f3ad4 | 2017-09-19 14:41:07 +0200 | [diff] [blame] | 95 | } |
Martin Polreich | a3e3012 | 2017-08-22 12:43:55 +0200 | [diff] [blame] | 96 | } |
Martin Polreich | a3e3012 | 2017-08-22 12:43:55 +0200 | [diff] [blame] | 97 | } |
Martin Polreich | b33d23e | 2017-09-01 15:22:16 +0000 | [diff] [blame] | 98 | } |