blob: 4edcdb71675f8924e812e32194a8e6daba5a4f77 [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
chnyda03f3ad42017-09-19 14:41:07 +020022throttle(['test-formula']) {
23 node("python") {
24 try {
25 stage("checkout") {
26 if (defaultGitRef && defaultGitUrl) {
27 checkouted = gerrit.gerritPatchsetCheckout(defaultGitUrl, defaultGitRef, "HEAD", CREDENTIALS_ID)
Martin Polreicha3e30122017-08-22 12:43:55 +020028 } else {
chnyda03f3ad42017-09-19 14:41:07 +020029 throw new Exception("Cannot checkout gerrit patchset, DEFAULT_GIT_REF is null")
Martin Polreicha3e30122017-08-22 12:43:55 +020030 }
31 }
chnyda03f3ad42017-09-19 14:41:07 +020032 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 Polreicha3e30122017-08-22 12:43:55 +020092 }
Martin Polreicha3e30122017-08-22 12:43:55 +020093 }
Martin Polreichb33d23e2017-09-01 15:22:16 +000094}