blob: b8d842dacc316b5c0a7fd792fb7bb7dd15b3cc75 [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 }
31 stage("test") {
32 if (checkouted) {
33 sh("make clean")
34 sh("[ $SALT_VERSION != 'latest' ] || export SALT_VERSION=''; make test")
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")
Martin Polreich9a1d16b2017-08-29 17:16:12 +020064 if (KITCHEN_ENV != null && !KITCHEN_ENV.isEmpty() && KITCHEN_ENV != "") {
Martin Polreicha3e30122017-08-22 12:43:55 +020065 def cleanEnv = KITCHEN_ENV.replaceAll("\\s?SUITE=[^\\s]*", "")
66 def suitePattern = java.util.regex.Pattern.compile("\\s?SUITE=([^\\s]*)")
67 def suiteMatcher = suitePattern.matcher(KITCHEN_ENV)
68 if (suiteMatcher.find()) {
69 def suite = suiteMatcher.group(1)
Martin Polreich9a1d16b2017-08-29 17:16:12 +020070 suiteMatcher = null
Martin Polreicha3e30122017-08-22 12:43:55 +020071 def cleanSuite = suite.replaceAll("_", "-")
Martin Polreich9a1d16b2017-08-29 17:16:12 +020072 common.infoMsg("Running kitchen test with environment:" + KITCHEN_ENV.trim())
Martin Polreicha3e30122017-08-22 12:43:55 +020073 ruby.runKitchenTests(cleanEnv, cleanSuite)
74 } else {
75 common.warningMsg("No SUITE was found. Running with all suites.")
76 ruby.runKitchenTests(cleanEnv, "")
77 }
78 } else {
79 throw new Exception("KITCHEN_ENV parameter is empty or invalid. This may indicate wrong env settings of initial test job or .travis.yml file.")
80 }
81 } else {
82 throw new Exception(".kitchen.yml file not found, no kitchen tests triggered.")
83 }
84 }
85 }
86 } catch (Throwable e) {
87 // If there was an error or exception thrown, the build failed
88 currentBuild.result = "FAILURE"
89 ruby.runKitchenCommand("destroy")
90 throw e
91 } finally {
92 if (currentBuild.result == "FAILURE" && fileExists(".kitchen/logs/kitchen.log")) {
93 common.errorMsg("----------------KITCHEN LOG:---------------")
94 println readFile(".kitchen/logs/kitchen.log")
95 }
96 common.sendNotification(currentBuild.result, "", ["slack"])
97 }
98}