blob: 8ad5f1c1c0b90477b7d175abb21df28c6ef61fb5 [file] [log] [blame]
Jakub Josef83379312017-03-29 18:12:34 +02001/**
2 * Test salt formulas pipeline
3 * DEFAULT_GIT_REF
4 * DEFAULT_GIT_URL
5 * CREDENTIALS_ID
Jakub Josef0bbbd802017-05-22 20:28:44 +02006 * KITCHEN_TESTS_PARALLEL
Jakub Josef83379312017-03-29 18:12:34 +02007 */
Jakub Josefc5a223a2017-03-01 14:40:08 +01008def common = new com.mirantis.mk.Common()
9def gerrit = new com.mirantis.mk.Gerrit()
Jakub Joseff64c6392017-05-03 13:18:25 +020010def ruby = new com.mirantis.mk.Ruby()
Jakub Josef83379312017-03-29 18:12:34 +020011
12def gerritRef
13try {
14 gerritRef = GERRIT_REFSPEC
15} catch (MissingPropertyException e) {
16 gerritRef = null
17}
18
19def defaultGitRef, defaultGitUrl
20try {
21 defaultGitRef = DEFAULT_GIT_REF
22 defaultGitUrl = DEFAULT_GIT_URL
23} catch (MissingPropertyException e) {
24 defaultGitRef = null
25 defaultGitUrl = null
26}
27
Jakub Josefbcd2e902017-06-13 14:40:41 +020028def checkouted = false
Jakub Josef83379312017-03-29 18:12:34 +020029
chnyda3b1d2a62017-06-13 10:08:12 +020030node("python") {
Jakub Josefc5a223a2017-03-01 14:40:08 +010031 try{
32 stage("checkout") {
Jakub Josef83379312017-03-29 18:12:34 +020033 if (gerritRef) {
34 // job is triggered by Gerrit
Jakub Josefb2235902017-06-16 12:49:16 +020035 def gerritChange = gerrit.getGerritChange(GERRIT_NAME, GERRIT_HOST, GERRIT_CHANGE_NUMBER, CREDENTIALS_ID, true)
36 // test if gerrit change is already Verified
Jakub Josef2ed50812017-06-16 14:56:58 +020037 if(gerrit.patchsetHasApproval(gerritChange.currentPatchSet,"Verified","+")){
Jakub Josef894f1e32017-06-19 16:24:19 +000038 common.successMsg("Gerrit change ${GERRIT_CHANGE_NUMBER} patchset ${GERRIT_PATCHSET_NUMBER} already has Verified, skipping tests") // do nothing
Jakub Josefbcd2e902017-06-13 14:40:41 +020039 // test WIP contains in commit message
Jakub Josefb2235902017-06-16 12:49:16 +020040 }else if(gerritChange.commitMessage.contains("WIP")){
Jakub Josef894f1e32017-06-19 16:24:19 +000041 common.successMsg("Commit message contains WIP, skipping tests") // do nothing
Jakub Josefbcd2e902017-06-13 14:40:41 +020042 }else{
43 // test if change aren't already merged
44 def merged = gerritChange.status == "MERGED"
45 if(!merged){
46 checkouted = gerrit.gerritPatchsetCheckout ([
47 credentialsId : CREDENTIALS_ID
48 ])
49 } else{
50 common.successMsg("Change ${GERRIT_CHANGE_NUMBER} is already merged, no need to test them")
51 }
Jakub Josef740a7882017-06-01 14:54:01 +020052 }
Jakub Josef83379312017-03-29 18:12:34 +020053 } else if(defaultGitRef && defaultGitUrl) {
Jakub Josefe1407ac2017-03-30 14:10:19 +020054 checkouted = gerrit.gerritPatchsetCheckout(defaultGitUrl, defaultGitRef, "HEAD", CREDENTIALS_ID)
Jakub Josefbcd2e902017-06-13 14:40:41 +020055 } else {
Jakub Josef5ce6a362017-03-31 13:41:17 +020056 throw new Exception("Cannot checkout gerrit patchset, GERRIT_REFSPEC and DEFAULT_GIT_REF is null")
Jakub Josef83379312017-03-29 18:12:34 +020057 }
Jakub Josefc5a223a2017-03-01 14:40:08 +010058 }
59 stage("test") {
Jakub Josef83379312017-03-29 18:12:34 +020060 if(checkouted){
Ruslan Kamaldinov310ffc02017-08-08 16:07:42 +040061 sh("make clean")
62 sh("[ $SALT_VERSION != 'latest' ] || export SALT_VERSION=''; make test")
Jakub Josefc5a223a2017-03-01 14:40:08 +010063 }
64 }
Jakub Joseff64c6392017-05-03 13:18:25 +020065 stage("kitchen") {
Jakub Josefbcd2e902017-06-13 14:40:41 +020066 if(checkouted){
67 if (fileExists(".kitchen.yml")) {
68 common.infoMsg(".kitchen.yml found, running kitchen tests")
69 ruby.ensureRubyEnv()
70 def kitchenEnvs = []
Martin Polreich9b5f5ab2017-07-12 13:06:14 +020071 def filteredEnvs = []
Jakub Josefbcd2e902017-06-13 14:40:41 +020072 if(fileExists(".travis.yml")){
73 common.infoMsg(".travis.yml found, running custom kitchen init")
74 def kitchenConfigYML = readYaml(file: ".travis.yml")
Jakub Josef904972f2017-07-17 15:57:35 +020075 if(kitchenConfigYML.containsKey("env")){
76 kitchenEnvs=kitchenConfigYML["env"]
77 }
Jakub Josefbcd2e902017-06-13 14:40:41 +020078 def kitchenInit = kitchenConfigYML["install"]
79 def kitchenInstalled = false
80 if(kitchenInit && !kitchenInit.isEmpty()){
Jakub Josef96254e22017-07-17 14:36:02 +020081 for(int i=0; i<kitchenInit.size(); i++){
Jakub Josefbcd2e902017-06-13 14:40:41 +020082 if(kitchenInit[i].trim().startsWith("test -e Gemfile")){ //found Gemfile config
83 common.infoMsg("Custom Gemfile configuration found, using them")
84 ruby.installKitchen(kitchenInit[i].trim())
85 kitchenInstalled = true
86 }
Jakub Josefcca1e312017-05-23 15:21:35 +020087 }
Jakub Josefd672e402017-05-23 12:03:44 +020088 }
Jakub Josefbcd2e902017-06-13 14:40:41 +020089 if(!kitchenInstalled){
90 ruby.installKitchen()
Jakub Josef0bbbd802017-05-22 20:28:44 +020091 }
92 }else{
Jakub Josefbcd2e902017-06-13 14:40:41 +020093 common.infoMsg(".travis.yml not found, running default kitchen init")
94 ruby.installKitchen()
Jakub Josef0bbbd802017-05-22 20:28:44 +020095 }
Jakub Josefbcd2e902017-06-13 14:40:41 +020096 common.infoMsg("Running kitchen testing, parallel mode: " + KITCHEN_TESTS_PARALLEL.toBoolean())
Ruslan Kamaldinov310ffc02017-08-08 16:07:42 +040097
98 if(CUSTOM_KITCHEN_ENVS != null && CUSTOM_KITCHEN_ENVS != ''){
99 filteredEnvs = CUSTOM_KITCHEN_ENVS.tokenize('\n')
Martin Polreich62336792017-07-18 14:12:14 +0200100 } else {
Ruslan Kamaldinov310ffc02017-08-08 16:07:42 +0400101 filteredEnvs = ruby.filterKitchenEnvs(kitchenEnvs).unique()
Jakub Josefbcd2e902017-06-13 14:40:41 +0200102 }
Ruslan Kamaldinov310ffc02017-08-08 16:07:42 +0400103 // Allow custom filteredEnvs in case of empty kitchenEnvs
104 if((kitchenEnvs && !kitchenEnvs.isEmpty() && !filteredEnvs.isEmpty()) || ((kitchenEnvs==null || kitchenEnvs=='') && !filteredEnvs.isEmpty())){
105 for(int i=0; i<filteredEnvs.size(); i++){
106 common.infoMsg("Found " + filteredEnvs.size() + " environment, kitchen running with env number " + (i+1) + ": " + filteredEnvs[i].trim())
107 ruby.runKitchenTests(filteredEnvs[i].trim(), KITCHEN_TESTS_PARALLEL.toBoolean())
108 }
109 } else {
110 ruby.runKitchenTests("", KITCHEN_TESTS_PARALLEL.toBoolean())
Jakub Josefbcd2e902017-06-13 14:40:41 +0200111 }
112 } else {
113 common.infoMsg(".kitchen.yml not found")
Jakub Joseff64c6392017-05-03 13:18:25 +0200114 }
Jakub Joseff64c6392017-05-03 13:18:25 +0200115 }
116 }
Jakub Josefc5a223a2017-03-01 14:40:08 +0100117 } catch (Throwable e) {
118 // If there was an error or exception thrown, the build failed
119 currentBuild.result = "FAILURE"
Jakub Josefd11bdcc2017-06-13 17:02:43 +0200120 ruby.runKitchenCommand("destroy")
Jakub Josefc5a223a2017-03-01 14:40:08 +0100121 throw e
122 } finally {
Jakub Josef52baaa42017-05-04 12:20:54 +0200123 if(currentBuild.result == "FAILURE" && fileExists(".kitchen/logs/kitchen.log")){
Jakub Joseff96ebc52017-05-04 12:37:19 +0200124 common.errorMsg("----------------KITCHEN LOG:---------------")
Jakub Josef52baaa42017-05-04 12:20:54 +0200125 println readFile(".kitchen/logs/kitchen.log")
126 }
Jakub Josefc5a223a2017-03-01 14:40:08 +0100127 common.sendNotification(currentBuild.result,"",["slack"])
128 }
Jakub Josefd283f8c2017-05-10 18:20:11 +0200129}
130