Martin Polreich | a3e3012 | 2017-08-22 12:43:55 +0200 | [diff] [blame] | 1 | /** |
| 2 | * Test salt formulas pipeline |
| 3 | * DEFAULT_GIT_REF |
| 4 | * DEFAULT_GIT_URL |
| 5 | * CREDENTIALS_ID |
| 6 | */ |
| 7 | def common = new com.mirantis.mk.Common() |
| 8 | def ruby = new com.mirantis.mk.Ruby() |
Martin Polreich | 9a1d16b | 2017-08-29 17:16:12 +0200 | [diff] [blame] | 9 | def gerrit = new com.mirantis.mk.Gerrit() |
Martin Polreich | a3e3012 | 2017-08-22 12:43:55 +0200 | [diff] [blame] | 10 | |
| 11 | def defaultGitRef, defaultGitUrl |
| 12 | try { |
| 13 | defaultGitRef = DEFAULT_GIT_REF |
| 14 | defaultGitUrl = DEFAULT_GIT_URL |
| 15 | } catch (MissingPropertyException e) { |
| 16 | defaultGitRef = null |
| 17 | defaultGitUrl = null |
| 18 | } |
| 19 | |
| 20 | def checkouted = false |
Martin Polreich | c0995dc | 2018-11-05 14:40:02 +0100 | [diff] [blame^] | 21 | def openstackTest = false |
Martin Polreich | a3e3012 | 2017-08-22 12:43:55 +0200 | [diff] [blame] | 22 | |
chnyda | 03f3ad4 | 2017-09-19 14:41:07 +0200 | [diff] [blame] | 23 | throttle(['test-formula']) { |
Jakub Josef | db3ddd8 | 2018-01-23 13:30:47 +0100 | [diff] [blame] | 24 | timeout(time: 1, unit: 'HOURS') { |
Jakub Josef | 22815b0 | 2018-01-30 16:05:26 +0100 | [diff] [blame] | 25 | node("python&&docker") { |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 26 | try { |
| 27 | stage("checkout") { |
| 28 | if (defaultGitRef && defaultGitUrl) { |
| 29 | checkouted = gerrit.gerritPatchsetCheckout(defaultGitUrl, defaultGitRef, "HEAD", CREDENTIALS_ID) |
chnyda | 03f3ad4 | 2017-09-19 14:41:07 +0200 | [diff] [blame] | 30 | } else { |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 31 | throw new Exception("Cannot checkout gerrit patchset, DEFAULT_GIT_REF is null") |
chnyda | 03f3ad4 | 2017-09-19 14:41:07 +0200 | [diff] [blame] | 32 | } |
| 33 | } |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 34 | stage("cleanup") { |
| 35 | if (checkouted) { |
| 36 | sh("make clean") |
| 37 | } |
| 38 | } |
| 39 | stage("kitchen") { |
| 40 | if (checkouted) { |
Martin Polreich | c0995dc | 2018-11-05 14:40:02 +0100 | [diff] [blame^] | 41 | 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 Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 51 | 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 Polreich | c0995dc | 2018-11-05 14:40:02 +0100 | [diff] [blame^] | 58 | 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 Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 73 | } |
| 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 Evseev | 227b8c7 | 2018-10-25 15:40:34 +0200 | [diff] [blame] | 86 | 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 Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 88 | 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 | } |
chnyda | 03f3ad4 | 2017-09-19 14:41:07 +0200 | [diff] [blame] | 114 | } |
Martin Polreich | a3e3012 | 2017-08-22 12:43:55 +0200 | [diff] [blame] | 115 | } |
Martin Polreich | a3e3012 | 2017-08-22 12:43:55 +0200 | [diff] [blame] | 116 | } |
Martin Polreich | b33d23e | 2017-09-01 15:22:16 +0000 | [diff] [blame] | 117 | } |