blob: 8f607270e5acaebbf9a6949e9d65a06bef01cc82 [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']) {
Jakub Josefa63f9862018-01-11 17:58:38 +010023 timeout(time: 12, unit: 'HOURS') {
24 node("python") {
25 try {
26 stage("checkout") {
27 if (defaultGitRef && defaultGitUrl) {
28 checkouted = gerrit.gerritPatchsetCheckout(defaultGitUrl, defaultGitRef, "HEAD", CREDENTIALS_ID)
chnyda03f3ad42017-09-19 14:41:07 +020029 } else {
Jakub Josefa63f9862018-01-11 17:58:38 +010030 throw new Exception("Cannot checkout gerrit patchset, DEFAULT_GIT_REF is null")
chnyda03f3ad42017-09-19 14:41:07 +020031 }
32 }
Jakub Josefa63f9862018-01-11 17:58:38 +010033 stage("cleanup") {
34 if (checkouted) {
35 sh("make clean")
36 }
37 }
38 stage("kitchen") {
39 if (checkouted) {
40 if (fileExists(".kitchen.yml")) {
41 common.infoMsg(".kitchen.yml found, running kitchen tests")
42 ruby.ensureRubyEnv()
43 if (fileExists(".travis.yml")) {
44 common.infoMsg(".travis.yml found, running custom kitchen init")
45 def kitchenConfigYML = readYaml(file: ".travis.yml")
46 def kitchenInit = kitchenConfigYML["install"]
47 def kitchenInstalled = false
48 if (kitchenInit && !kitchenInit.isEmpty()) {
49 for (int i = 0; i < kitchenInit.size(); i++) {
50 if (kitchenInit[i].trim().startsWith("test -e Gemfile")) { //found Gemfile config
51 common.infoMsg("Custom Gemfile configuration found, using them")
52 ruby.installKitchen(kitchenInit[i].trim())
53 kitchenInstalled = true
54 }
55 }
56 }
57 if (!kitchenInstalled) {
58 ruby.installKitchen()
59 }
60 } else {
61 common.infoMsg(".travis.yml not found, running default kitchen init")
62 ruby.installKitchen()
63 }
64 common.infoMsg("Running part of kitchen test")
65 if (KITCHEN_ENV != null && !KITCHEN_ENV.isEmpty() && KITCHEN_ENV != "") {
66 def cleanEnv = KITCHEN_ENV.replaceAll("\\s?SUITE=[^\\s]*", "")
67 sh("find . -type f -exec sed -i 's/apt.mirantis.com/apt.mirantis.net:8085/g' {} \\;")
68 sh("find . -type f -exec sed -i 's/apt-mk.mirantis.com/apt.mirantis.net:8085/g' {} \\;")
69 def suite = ruby.getSuiteName(KITCHEN_ENV)
70 if (suite && suite != "") {
71 common.infoMsg("Running kitchen test with environment:" + KITCHEN_ENV.trim())
72 ruby.runKitchenTests(cleanEnv, suite)
73 } 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 }
chnyda03f3ad42017-09-19 14:41:07 +020095 }
Martin Polreicha3e30122017-08-22 12:43:55 +020096 }
Martin Polreicha3e30122017-08-22 12:43:55 +020097 }
Martin Polreichb33d23e2017-09-01 15:22:16 +000098}