blob: 64b089e76d88003ad2484f39678d69f379e014de [file] [log] [blame]
Martin Polreicha3e30122017-08-22 12:43:55 +02001/**
2 * Test salt formulas pipeline
3 * DEFAULT_GIT_REF
4 * DEFAULT_GIT_URL
5 * CREDENTIALS_ID
6 */
7def common = new com.mirantis.mk.Common()
8def ruby = new com.mirantis.mk.Ruby()
Martin Polreich9a1d16b2017-08-29 17:16:12 +02009def gerrit = new com.mirantis.mk.Gerrit()
Martin Polreicha3e30122017-08-22 12:43:55 +020010
11def defaultGitRef, defaultGitUrl
12try {
13 defaultGitRef = DEFAULT_GIT_REF
14 defaultGitUrl = DEFAULT_GIT_URL
15} catch (MissingPropertyException e) {
16 defaultGitRef = null
17 defaultGitUrl = null
18}
19
20def checkouted = false
21
22node("python") {
23 try {
24 stage("checkout") {
25 if (defaultGitRef && defaultGitUrl) {
26 checkouted = gerrit.gerritPatchsetCheckout(defaultGitUrl, defaultGitRef, "HEAD", CREDENTIALS_ID)
27 } else {
28 throw new Exception("Cannot checkout gerrit patchset, DEFAULT_GIT_REF is null")
29 }
30 }
chnyda62dcf642017-08-31 10:28:36 +020031 stage("cleanup") {
Martin Polreicha3e30122017-08-22 12:43:55 +020032 if (checkouted) {
33 sh("make clean")
Martin Polreicha3e30122017-08-22 12:43:55 +020034 }
35 }
36 stage("kitchen") {
37 if (checkouted) {
38 if (fileExists(".kitchen.yml")) {
39 common.infoMsg(".kitchen.yml found, running kitchen tests")
40 ruby.ensureRubyEnv()
41 if (fileExists(".travis.yml")) {
42 common.infoMsg(".travis.yml found, running custom kitchen init")
43 def kitchenConfigYML = readYaml(file: ".travis.yml")
44 def kitchenInit = kitchenConfigYML["install"]
45 def kitchenInstalled = false
46 if (kitchenInit && !kitchenInit.isEmpty()) {
47 for (int i = 0; i < kitchenInit.size(); i++) {
48 if (kitchenInit[i].trim().startsWith("test -e Gemfile")) { //found Gemfile config
49 common.infoMsg("Custom Gemfile configuration found, using them")
50 ruby.installKitchen(kitchenInit[i].trim())
51 kitchenInstalled = true
52 }
53 }
54 }
55 if (!kitchenInstalled) {
56 ruby.installKitchen()
57 }
58 } else {
59 common.infoMsg(".travis.yml not found, running default kitchen init")
60 ruby.installKitchen()
61 }
62 common.infoMsg("Running part of kitchen test")
Martin Polreich9a1d16b2017-08-29 17:16:12 +020063 if (KITCHEN_ENV != null && !KITCHEN_ENV.isEmpty() && KITCHEN_ENV != "") {
Martin Polreicha3e30122017-08-22 12:43:55 +020064 def cleanEnv = KITCHEN_ENV.replaceAll("\\s?SUITE=[^\\s]*", "")
Martin Polreichde64efe2017-09-01 15:18:55 +000065 def suitePattern = java.util.regex.Pattern.compile("\\s?SUITE=([^\\s]*)")
66 def suiteMatcher = suitePattern.matcher(KITCHEN_ENV)
67 if (suiteMatcher.find()) {
68 def suite = suiteMatcher.group(1)
69 suiteMatcher = null
70 def cleanSuite = suite.replaceAll("_", "-")
Martin Polreich9a1d16b2017-08-29 17:16:12 +020071 common.infoMsg("Running kitchen test with environment:" + KITCHEN_ENV.trim())
Martin Polreichde64efe2017-09-01 15:18:55 +000072 ruby.runKitchenTests(cleanEnv, cleanSuite)
Martin Polreicha3e30122017-08-22 12:43:55 +020073 } 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 }
Martin Polreicha3e30122017-08-22 12:43:55 +020095 }
Martin Polreichde64efe2017-09-01 15:18:55 +000096}