Jakub Josef | 8337931 | 2017-03-29 18:12:34 +0200 | [diff] [blame] | 1 | /** |
| 2 | * Test salt formulas pipeline |
| 3 | * DEFAULT_GIT_REF |
| 4 | * DEFAULT_GIT_URL |
| 5 | * CREDENTIALS_ID |
| 6 | */ |
Jakub Josef | c5a223a | 2017-03-01 14:40:08 +0100 | [diff] [blame] | 7 | def common = new com.mirantis.mk.Common() |
| 8 | def gerrit = new com.mirantis.mk.Gerrit() |
Jakub Josef | f64c639 | 2017-05-03 13:18:25 +0200 | [diff] [blame] | 9 | def ruby = new com.mirantis.mk.Ruby() |
Jakub Josef | 8337931 | 2017-03-29 18:12:34 +0200 | [diff] [blame] | 10 | |
| 11 | def gerritRef |
| 12 | try { |
| 13 | gerritRef = GERRIT_REFSPEC |
| 14 | } catch (MissingPropertyException e) { |
| 15 | gerritRef = null |
| 16 | } |
| 17 | |
| 18 | def defaultGitRef, defaultGitUrl |
| 19 | try { |
| 20 | defaultGitRef = DEFAULT_GIT_REF |
| 21 | defaultGitUrl = DEFAULT_GIT_URL |
| 22 | } catch (MissingPropertyException e) { |
| 23 | defaultGitRef = null |
| 24 | defaultGitUrl = null |
| 25 | } |
| 26 | |
| 27 | def checkouted = false; |
| 28 | |
Jakub Josef | 52baaa4 | 2017-05-04 12:20:54 +0200 | [diff] [blame] | 29 | node("python&&docker") { |
Jakub Josef | c5a223a | 2017-03-01 14:40:08 +0100 | [diff] [blame] | 30 | try{ |
| 31 | stage("checkout") { |
Jakub Josef | 8337931 | 2017-03-29 18:12:34 +0200 | [diff] [blame] | 32 | if (gerritRef) { |
| 33 | // job is triggered by Gerrit |
| 34 | checkouted = gerrit.gerritPatchsetCheckout ([ |
Jakub Josef | c5a223a | 2017-03-01 14:40:08 +0100 | [diff] [blame] | 35 | credentialsId : CREDENTIALS_ID |
Jakub Josef | 8337931 | 2017-03-29 18:12:34 +0200 | [diff] [blame] | 36 | ]) |
| 37 | } else if(defaultGitRef && defaultGitUrl) { |
Jakub Josef | e1407ac | 2017-03-30 14:10:19 +0200 | [diff] [blame] | 38 | checkouted = gerrit.gerritPatchsetCheckout(defaultGitUrl, defaultGitRef, "HEAD", CREDENTIALS_ID) |
Jakub Josef | 8337931 | 2017-03-29 18:12:34 +0200 | [diff] [blame] | 39 | } |
| 40 | if(!checkouted){ |
Jakub Josef | 5ce6a36 | 2017-03-31 13:41:17 +0200 | [diff] [blame] | 41 | throw new Exception("Cannot checkout gerrit patchset, GERRIT_REFSPEC and DEFAULT_GIT_REF is null") |
Jakub Josef | 8337931 | 2017-03-29 18:12:34 +0200 | [diff] [blame] | 42 | } |
Jakub Josef | c5a223a | 2017-03-01 14:40:08 +0100 | [diff] [blame] | 43 | } |
| 44 | stage("test") { |
Jakub Josef | 8337931 | 2017-03-29 18:12:34 +0200 | [diff] [blame] | 45 | if(checkouted){ |
| 46 | wrap([$class: 'AnsiColorBuildWrapper']) { |
| 47 | sh("make clean") |
| 48 | sh("[ $SALT_VERSION != 'latest' ] || export SALT_VERSION=''; make test") |
| 49 | } |
Jakub Josef | c5a223a | 2017-03-01 14:40:08 +0100 | [diff] [blame] | 50 | } |
| 51 | } |
Jakub Josef | f64c639 | 2017-05-03 13:18:25 +0200 | [diff] [blame] | 52 | stage("kitchen") { |
| 53 | if (fileExists(".kitchen.yml")) { |
Jakub Josef | 52baaa4 | 2017-05-04 12:20:54 +0200 | [diff] [blame] | 54 | common.infoMsg(".kitchen.yml found, running kitchen tests") |
Jakub Josef | f64c639 | 2017-05-03 13:18:25 +0200 | [diff] [blame] | 55 | ruby.ensureRubyEnv() |
| 56 | ruby.installKitchen() |
| 57 | wrap([$class: 'AnsiColorBuildWrapper']) { |
| 58 | ruby.runKitchenTests() |
| 59 | } |
| 60 | } else { |
| 61 | common.infoMsg(".kitchen.yml not found") |
| 62 | } |
| 63 | } |
Jakub Josef | c5a223a | 2017-03-01 14:40:08 +0100 | [diff] [blame] | 64 | } catch (Throwable e) { |
| 65 | // If there was an error or exception thrown, the build failed |
| 66 | currentBuild.result = "FAILURE" |
| 67 | throw e |
| 68 | } finally { |
Jakub Josef | 52baaa4 | 2017-05-04 12:20:54 +0200 | [diff] [blame] | 69 | if(currentBuild.result == "FAILURE" && fileExists(".kitchen/logs/kitchen.log")){ |
Jakub Josef | f96ebc5 | 2017-05-04 12:37:19 +0200 | [diff] [blame] | 70 | common.errorMsg("----------------KITCHEN LOG:---------------") |
Jakub Josef | 52baaa4 | 2017-05-04 12:20:54 +0200 | [diff] [blame] | 71 | println readFile(".kitchen/logs/kitchen.log") |
| 72 | } |
Jakub Josef | c5a223a | 2017-03-01 14:40:08 +0100 | [diff] [blame] | 73 | common.sendNotification(currentBuild.result,"",["slack"]) |
| 74 | } |
| 75 | } |