blob: 1f646b9706d0265eba36c805de24f6520efd43fb [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 Polreichb33d23e2017-09-01 15:22:16 +000065 def suite = ruby.getSuiteName(KITCHEN_ENV)
66 if (suite && suite != "") {
Martin Polreich9a1d16b2017-08-29 17:16:12 +020067 common.infoMsg("Running kitchen test with environment:" + KITCHEN_ENV.trim())
Martin Polreichb33d23e2017-09-01 15:22:16 +000068 ruby.runKitchenTests(cleanEnv, suite)
Martin Polreicha3e30122017-08-22 12:43:55 +020069 } else {
70 common.warningMsg("No SUITE was found. Running with all suites.")
71 ruby.runKitchenTests(cleanEnv, "")
72 }
73 } else {
74 throw new Exception("KITCHEN_ENV parameter is empty or invalid. This may indicate wrong env settings of initial test job or .travis.yml file.")
75 }
76 } else {
77 throw new Exception(".kitchen.yml file not found, no kitchen tests triggered.")
78 }
79 }
80 }
81 } catch (Throwable e) {
82 // If there was an error or exception thrown, the build failed
83 currentBuild.result = "FAILURE"
84 ruby.runKitchenCommand("destroy")
85 throw e
86 } finally {
87 if (currentBuild.result == "FAILURE" && fileExists(".kitchen/logs/kitchen.log")) {
88 common.errorMsg("----------------KITCHEN LOG:---------------")
89 println readFile(".kitchen/logs/kitchen.log")
90 }
Martin Polreicha3e30122017-08-22 12:43:55 +020091 }
Martin Polreichb33d23e2017-09-01 15:22:16 +000092}