blob: 608182e01dc77ffb8020d0f8dee33944599bd702 [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
Martin Polreichc0995dc2018-11-05 14:40:02 +010021def openstackTest = false
Martin Polreicha3e30122017-08-22 12:43:55 +020022
chnyda03f3ad42017-09-19 14:41:07 +020023throttle(['test-formula']) {
Jakub Josefdb3ddd82018-01-23 13:30:47 +010024 timeout(time: 1, unit: 'HOURS') {
Jakub Josef22815b02018-01-30 16:05:26 +010025 node("python&&docker") {
Jakub Josefa63f9862018-01-11 17:58:38 +010026 try {
27 stage("checkout") {
28 if (defaultGitRef && defaultGitUrl) {
29 checkouted = gerrit.gerritPatchsetCheckout(defaultGitUrl, defaultGitRef, "HEAD", CREDENTIALS_ID)
chnyda03f3ad42017-09-19 14:41:07 +020030 } else {
Jakub Josefa63f9862018-01-11 17:58:38 +010031 throw new Exception("Cannot checkout gerrit patchset, DEFAULT_GIT_REF is null")
chnyda03f3ad42017-09-19 14:41:07 +020032 }
33 }
Jakub Josefa63f9862018-01-11 17:58:38 +010034 stage("cleanup") {
35 if (checkouted) {
36 sh("make clean")
37 }
38 }
39 stage("kitchen") {
40 if (checkouted) {
Martin Polreichc0995dc2018-11-05 14:40:02 +010041 if (fileExists(".kitchen.yml") || fileExists(".kitchen.openstack.yml")) {
42 if (fileExists(".kitchen.openstack.yml")) {
43 common.infoMsg("Openstack Kitchen test configuration found, running Openstack kitchen tests.")
44 if (fileExists(".kitchen.yml")) {
45 common.infoMsg("Ignoring the docker Kitchen test configuration file.")
46 }
47 openstackTest = true
48 } else {
49 common.infoMsg("Docker Kitchen test configuration found, running Docker kitchen tests.")
50 }
Jakub Josefa63f9862018-01-11 17:58:38 +010051 ruby.ensureRubyEnv()
52 if (fileExists(".travis.yml")) {
53 common.infoMsg(".travis.yml found, running custom kitchen init")
54 def kitchenConfigYML = readYaml(file: ".travis.yml")
55 def kitchenInit = kitchenConfigYML["install"]
56 def kitchenInstalled = false
57 if (kitchenInit && !kitchenInit.isEmpty()) {
Martin Polreichc0995dc2018-11-05 14:40:02 +010058 if (!openstackTest) {
59 for (int i = 0; i < kitchenInit.size(); i++) {
60 if (kitchenInit[i].trim().startsWith("test -e Gemfile")) { //found Gemfile config
61 common.infoMsg("Custom Gemfile configuration found, using them")
62 ruby.installKitchen(kitchenInit[i].trim())
63 kitchenInstalled = true
64 }
65 }
66 } else {
67 for (int i = 0; i < kitchenInit.size(); i++) {
68 if (kitchenInit[i].trim().startsWith("git clone")) { //found Gemfile config TODO: Change keywords ??
69 common.infoMsg("Custom Gemfile configuration found, using them")
70 sh(kitchenInit[i].trim())
71 kitchenInstalled = true
72 }
Jakub Josefa63f9862018-01-11 17:58:38 +010073 }
74 }
75 }
76 if (!kitchenInstalled) {
77 ruby.installKitchen()
78 }
79 } else {
80 common.infoMsg(".travis.yml not found, running default kitchen init")
81 ruby.installKitchen()
82 }
83 common.infoMsg("Running part of kitchen test")
84 if (KITCHEN_ENV != null && !KITCHEN_ENV.isEmpty() && KITCHEN_ENV != "") {
85 def cleanEnv = KITCHEN_ENV.replaceAll("\\s?SUITE=[^\\s]*", "")
Alexander Evseev227b8c72018-10-25 15:40:34 +020086 sh("find . -type f -exec sed -i 's/apt.mirantis.com/apt.mcp.mirantis.net/g' {} \\;")
87 sh("find . -type f -exec sed -i 's/apt-mk.mirantis.com/apt.mcp.mirantis.net/g' {} \\;")
Jakub Josefa63f9862018-01-11 17:58:38 +010088 def suite = ruby.getSuiteName(KITCHEN_ENV)
89 if (suite && suite != "") {
90 common.infoMsg("Running kitchen test with environment:" + KITCHEN_ENV.trim())
91 ruby.runKitchenTests(cleanEnv, suite)
92 } else {
93 common.warningMsg("No SUITE was found. Running with all suites.")
94 ruby.runKitchenTests(cleanEnv, "")
95 }
96 } else {
97 throw new Exception("KITCHEN_ENV parameter is empty or invalid. This may indicate wrong env settings of initial test job or .travis.yml file.")
98 }
99 } else {
100 throw new Exception(".kitchen.yml file not found, no kitchen tests triggered.")
101 }
102 }
103 }
104 } catch (Throwable e) {
105 // If there was an error or exception thrown, the build failed
106 currentBuild.result = "FAILURE"
107 ruby.runKitchenCommand("destroy")
108 throw e
109 } finally {
110 if (currentBuild.result == "FAILURE" && fileExists(".kitchen/logs/kitchen.log")) {
111 common.errorMsg("----------------KITCHEN LOG:---------------")
112 println readFile(".kitchen/logs/kitchen.log")
113 }
chnyda03f3ad42017-09-19 14:41:07 +0200114 }
Martin Polreicha3e30122017-08-22 12:43:55 +0200115 }
Martin Polreicha3e30122017-08-22 12:43:55 +0200116 }
Martin Polreichb33d23e2017-09-01 15:22:16 +0000117}