blob: 0a4424708ecc65bb3e64dcd380159d5fc07f09ac [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){
Jakub Josefbcd2e902017-06-13 14:40:41 +020061 wrap([$class: 'AnsiColorBuildWrapper']) {
62 sh("make clean")
63 sh("[ $SALT_VERSION != 'latest' ] || export SALT_VERSION=''; make test")
Jakub Josef83379312017-03-29 18:12:34 +020064 }
Jakub Josefc5a223a2017-03-01 14:40:08 +010065 }
66 }
Jakub Joseff64c6392017-05-03 13:18:25 +020067 stage("kitchen") {
Jakub Josefbcd2e902017-06-13 14:40:41 +020068 if(checkouted){
69 if (fileExists(".kitchen.yml")) {
70 common.infoMsg(".kitchen.yml found, running kitchen tests")
71 ruby.ensureRubyEnv()
72 def kitchenEnvs = []
Martin Polreich9b5f5ab2017-07-12 13:06:14 +020073 def filteredEnvs = []
Jakub Josefbcd2e902017-06-13 14:40:41 +020074 if(fileExists(".travis.yml")){
75 common.infoMsg(".travis.yml found, running custom kitchen init")
76 def kitchenConfigYML = readYaml(file: ".travis.yml")
Jakub Josef904972f2017-07-17 15:57:35 +020077 if(kitchenConfigYML.containsKey("env")){
78 kitchenEnvs=kitchenConfigYML["env"]
79 }
Jakub Josefbcd2e902017-06-13 14:40:41 +020080 def kitchenInit = kitchenConfigYML["install"]
81 def kitchenInstalled = false
82 if(kitchenInit && !kitchenInit.isEmpty()){
Jakub Josef96254e22017-07-17 14:36:02 +020083 for(int i=0; i<kitchenInit.size(); i++){
Jakub Josefbcd2e902017-06-13 14:40:41 +020084 if(kitchenInit[i].trim().startsWith("test -e Gemfile")){ //found Gemfile config
85 common.infoMsg("Custom Gemfile configuration found, using them")
86 ruby.installKitchen(kitchenInit[i].trim())
87 kitchenInstalled = true
88 }
Jakub Josefcca1e312017-05-23 15:21:35 +020089 }
Jakub Josefd672e402017-05-23 12:03:44 +020090 }
Jakub Josefbcd2e902017-06-13 14:40:41 +020091 if(!kitchenInstalled){
92 ruby.installKitchen()
Jakub Josef0bbbd802017-05-22 20:28:44 +020093 }
94 }else{
Jakub Josefbcd2e902017-06-13 14:40:41 +020095 common.infoMsg(".travis.yml not found, running default kitchen init")
96 ruby.installKitchen()
Jakub Josef0bbbd802017-05-22 20:28:44 +020097 }
Jakub Josefbcd2e902017-06-13 14:40:41 +020098 common.infoMsg("Running kitchen testing, parallel mode: " + KITCHEN_TESTS_PARALLEL.toBoolean())
99 wrap([$class: 'AnsiColorBuildWrapper']) {
Martin Polreich62336792017-07-18 14:12:14 +0200100 if(CUSTOM_KITCHEN_ENVS != null && CUSTOM_KITCHEN_ENVS != ''){
101 filteredEnvs = CUSTOM_KITCHEN_ENVS.tokenize('\n')
102 } else {
103 filteredEnvs = ruby.filterKitchenEnvs(kitchenEnvs).unique()
Jakub Josefbcd2e902017-06-13 14:40:41 +0200104 }
Martin Polreich62336792017-07-18 14:12:14 +0200105 // Allow custom filteredEnvs in case of empty kitchenEnvs
106 if((kitchenEnvs && !kitchenEnvs.isEmpty() && !filteredEnvs.isEmpty()) || ((kitchenEnvs==null || kitchenEnvs=='') && !filteredEnvs.isEmpty())){
107 for(int i=0; i<filteredEnvs.size(); i++){
Martin Polreich9ad6c132017-07-19 15:01:09 +0200108 common.infoMsg("Found " + filteredEnvs.size() + " environment, kitchen running with env number " + (i+1) + ": " + filteredEnvs[i].trim())
Martin Polreich62336792017-07-18 14:12:14 +0200109 ruby.runKitchenTests(filteredEnvs[i].trim(), KITCHEN_TESTS_PARALLEL.toBoolean())
110 }
111 } else {
Jakub Josefbcd2e902017-06-13 14:40:41 +0200112 ruby.runKitchenTests("", KITCHEN_TESTS_PARALLEL.toBoolean())
113 }
114 }
115 } else {
116 common.infoMsg(".kitchen.yml not found")
Jakub Joseff64c6392017-05-03 13:18:25 +0200117 }
Jakub Joseff64c6392017-05-03 13:18:25 +0200118 }
119 }
Jakub Josefc5a223a2017-03-01 14:40:08 +0100120 } catch (Throwable e) {
121 // If there was an error or exception thrown, the build failed
122 currentBuild.result = "FAILURE"
Jakub Josefd11bdcc2017-06-13 17:02:43 +0200123 ruby.runKitchenCommand("destroy")
Jakub Josefc5a223a2017-03-01 14:40:08 +0100124 throw e
125 } finally {
Jakub Josef52baaa42017-05-04 12:20:54 +0200126 if(currentBuild.result == "FAILURE" && fileExists(".kitchen/logs/kitchen.log")){
Jakub Joseff96ebc52017-05-04 12:37:19 +0200127 common.errorMsg("----------------KITCHEN LOG:---------------")
Jakub Josef52baaa42017-05-04 12:20:54 +0200128 println readFile(".kitchen/logs/kitchen.log")
129 }
Jakub Josefc5a223a2017-03-01 14:40:08 +0100130 common.sendNotification(currentBuild.result,"",["slack"])
131 }
Jakub Josefd283f8c2017-05-10 18:20:11 +0200132}
133