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']) { |
| 23 | node("python") { |
| 24 | try { |
| 25 | stage("checkout") { |
| 26 | if (defaultGitRef && defaultGitUrl) { |
| 27 | checkouted = gerrit.gerritPatchsetCheckout(defaultGitUrl, defaultGitRef, "HEAD", CREDENTIALS_ID) |
Martin Polreich | a3e3012 | 2017-08-22 12:43:55 +0200 | [diff] [blame] | 28 | } else { |
chnyda | 03f3ad4 | 2017-09-19 14:41:07 +0200 | [diff] [blame] | 29 | throw new Exception("Cannot checkout gerrit patchset, DEFAULT_GIT_REF is null") |
Martin Polreich | a3e3012 | 2017-08-22 12:43:55 +0200 | [diff] [blame] | 30 | } |
| 31 | } |
chnyda | 03f3ad4 | 2017-09-19 14:41:07 +0200 | [diff] [blame] | 32 | stage("cleanup") { |
| 33 | if (checkouted) { |
| 34 | sh("make clean") |
| 35 | } |
| 36 | } |
| 37 | stage("kitchen") { |
| 38 | if (checkouted) { |
| 39 | if (fileExists(".kitchen.yml")) { |
| 40 | common.infoMsg(".kitchen.yml found, running kitchen tests") |
| 41 | ruby.ensureRubyEnv() |
| 42 | if (fileExists(".travis.yml")) { |
| 43 | common.infoMsg(".travis.yml found, running custom kitchen init") |
| 44 | def kitchenConfigYML = readYaml(file: ".travis.yml") |
| 45 | def kitchenInit = kitchenConfigYML["install"] |
| 46 | def kitchenInstalled = false |
| 47 | if (kitchenInit && !kitchenInit.isEmpty()) { |
| 48 | for (int i = 0; i < kitchenInit.size(); i++) { |
| 49 | if (kitchenInit[i].trim().startsWith("test -e Gemfile")) { //found Gemfile config |
| 50 | common.infoMsg("Custom Gemfile configuration found, using them") |
| 51 | ruby.installKitchen(kitchenInit[i].trim()) |
| 52 | kitchenInstalled = true |
| 53 | } |
| 54 | } |
| 55 | } |
| 56 | if (!kitchenInstalled) { |
| 57 | ruby.installKitchen() |
| 58 | } |
| 59 | } else { |
| 60 | common.infoMsg(".travis.yml not found, running default kitchen init") |
| 61 | ruby.installKitchen() |
| 62 | } |
| 63 | common.infoMsg("Running part of kitchen test") |
| 64 | if (KITCHEN_ENV != null && !KITCHEN_ENV.isEmpty() && KITCHEN_ENV != "") { |
| 65 | def cleanEnv = KITCHEN_ENV.replaceAll("\\s?SUITE=[^\\s]*", "") |
| 66 | def suite = ruby.getSuiteName(KITCHEN_ENV) |
| 67 | if (suite && suite != "") { |
| 68 | common.infoMsg("Running kitchen test with environment:" + KITCHEN_ENV.trim()) |
| 69 | ruby.runKitchenTests(cleanEnv, suite) |
| 70 | } else { |
| 71 | common.warningMsg("No SUITE was found. Running with all suites.") |
| 72 | ruby.runKitchenTests(cleanEnv, "") |
| 73 | } |
| 74 | } else { |
| 75 | throw new Exception("KITCHEN_ENV parameter is empty or invalid. This may indicate wrong env settings of initial test job or .travis.yml file.") |
| 76 | } |
| 77 | } else { |
| 78 | throw new Exception(".kitchen.yml file not found, no kitchen tests triggered.") |
| 79 | } |
| 80 | } |
| 81 | } |
| 82 | } catch (Throwable e) { |
| 83 | // If there was an error or exception thrown, the build failed |
| 84 | currentBuild.result = "FAILURE" |
| 85 | ruby.runKitchenCommand("destroy") |
| 86 | throw e |
| 87 | } finally { |
| 88 | if (currentBuild.result == "FAILURE" && fileExists(".kitchen/logs/kitchen.log")) { |
| 89 | common.errorMsg("----------------KITCHEN LOG:---------------") |
| 90 | println readFile(".kitchen/logs/kitchen.log") |
| 91 | } |
Martin Polreich | a3e3012 | 2017-08-22 12:43:55 +0200 | [diff] [blame] | 92 | } |
Martin Polreich | a3e3012 | 2017-08-22 12:43:55 +0200 | [diff] [blame] | 93 | } |
Martin Polreich | b33d23e | 2017-09-01 15:22:16 +0000 | [diff] [blame] | 94 | } |