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 | d283f8c | 2017-05-10 18:20:11 +0200 | [diff] [blame^] | 10 | def jenkinsUtils = new com.mirantis.mk.JenkinsUtils() |
Jakub Josef | 8337931 | 2017-03-29 18:12:34 +0200 | [diff] [blame] | 11 | |
| 12 | def gerritRef |
| 13 | try { |
| 14 | gerritRef = GERRIT_REFSPEC |
| 15 | } catch (MissingPropertyException e) { |
| 16 | gerritRef = null |
| 17 | } |
| 18 | |
| 19 | def defaultGitRef, defaultGitUrl |
| 20 | try { |
| 21 | defaultGitRef = DEFAULT_GIT_REF |
| 22 | defaultGitUrl = DEFAULT_GIT_URL |
| 23 | } catch (MissingPropertyException e) { |
| 24 | defaultGitRef = null |
| 25 | defaultGitUrl = null |
| 26 | } |
| 27 | |
| 28 | def checkouted = false; |
| 29 | |
Jakub Josef | 52baaa4 | 2017-05-04 12:20:54 +0200 | [diff] [blame] | 30 | node("python&&docker") { |
Jakub Josef | c5a223a | 2017-03-01 14:40:08 +0100 | [diff] [blame] | 31 | try{ |
Jakub Josef | d283f8c | 2017-05-10 18:20:11 +0200 | [diff] [blame^] | 32 | stage("stop old tests"){ |
| 33 | if (gerritRef) { |
| 34 | def runningTestBuildNums = _getRunningTriggeredTestsBuildNumbers(env["JOB_NAME"], GERRIT_CHANGE_NUMBER, GERRIT_PATCHET_NUMBER) |
| 35 | for(int i=0; i<runningTestBuildNums.size(); i++){ |
| 36 | Jenkins.instance.getItemByFullName(env["JOB_NAME"]).getBuildByNumber(runningTestBuildNums[i]).finish(hudson.model.Result.ABORTED, new java.io.IOException("Aborting build")); |
| 37 | } |
| 38 | } |
| 39 | } |
Jakub Josef | c5a223a | 2017-03-01 14:40:08 +0100 | [diff] [blame] | 40 | stage("checkout") { |
Jakub Josef | 8337931 | 2017-03-29 18:12:34 +0200 | [diff] [blame] | 41 | if (gerritRef) { |
| 42 | // job is triggered by Gerrit |
| 43 | checkouted = gerrit.gerritPatchsetCheckout ([ |
Jakub Josef | c5a223a | 2017-03-01 14:40:08 +0100 | [diff] [blame] | 44 | credentialsId : CREDENTIALS_ID |
Jakub Josef | 8337931 | 2017-03-29 18:12:34 +0200 | [diff] [blame] | 45 | ]) |
| 46 | } else if(defaultGitRef && defaultGitUrl) { |
Jakub Josef | e1407ac | 2017-03-30 14:10:19 +0200 | [diff] [blame] | 47 | checkouted = gerrit.gerritPatchsetCheckout(defaultGitUrl, defaultGitRef, "HEAD", CREDENTIALS_ID) |
Jakub Josef | 8337931 | 2017-03-29 18:12:34 +0200 | [diff] [blame] | 48 | } |
| 49 | if(!checkouted){ |
Jakub Josef | 5ce6a36 | 2017-03-31 13:41:17 +0200 | [diff] [blame] | 50 | 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] | 51 | } |
Jakub Josef | c5a223a | 2017-03-01 14:40:08 +0100 | [diff] [blame] | 52 | } |
| 53 | stage("test") { |
Jakub Josef | 8337931 | 2017-03-29 18:12:34 +0200 | [diff] [blame] | 54 | if(checkouted){ |
| 55 | wrap([$class: 'AnsiColorBuildWrapper']) { |
| 56 | sh("make clean") |
| 57 | sh("[ $SALT_VERSION != 'latest' ] || export SALT_VERSION=''; make test") |
| 58 | } |
Jakub Josef | c5a223a | 2017-03-01 14:40:08 +0100 | [diff] [blame] | 59 | } |
| 60 | } |
Jakub Josef | f64c639 | 2017-05-03 13:18:25 +0200 | [diff] [blame] | 61 | stage("kitchen") { |
| 62 | if (fileExists(".kitchen.yml")) { |
Jakub Josef | 52baaa4 | 2017-05-04 12:20:54 +0200 | [diff] [blame] | 63 | common.infoMsg(".kitchen.yml found, running kitchen tests") |
Jakub Josef | f64c639 | 2017-05-03 13:18:25 +0200 | [diff] [blame] | 64 | ruby.ensureRubyEnv() |
| 65 | ruby.installKitchen() |
| 66 | wrap([$class: 'AnsiColorBuildWrapper']) { |
| 67 | ruby.runKitchenTests() |
| 68 | } |
| 69 | } else { |
| 70 | common.infoMsg(".kitchen.yml not found") |
| 71 | } |
| 72 | } |
Jakub Josef | c5a223a | 2017-03-01 14:40:08 +0100 | [diff] [blame] | 73 | } catch (Throwable e) { |
| 74 | // If there was an error or exception thrown, the build failed |
| 75 | currentBuild.result = "FAILURE" |
| 76 | throw e |
| 77 | } finally { |
Jakub Josef | 52baaa4 | 2017-05-04 12:20:54 +0200 | [diff] [blame] | 78 | if(currentBuild.result == "FAILURE" && fileExists(".kitchen/logs/kitchen.log")){ |
Jakub Josef | f96ebc5 | 2017-05-04 12:37:19 +0200 | [diff] [blame] | 79 | common.errorMsg("----------------KITCHEN LOG:---------------") |
Jakub Josef | 52baaa4 | 2017-05-04 12:20:54 +0200 | [diff] [blame] | 80 | println readFile(".kitchen/logs/kitchen.log") |
| 81 | } |
Jakub Josef | c5a223a | 2017-03-01 14:40:08 +0100 | [diff] [blame] | 82 | common.sendNotification(currentBuild.result,"",["slack"]) |
| 83 | } |
Jakub Josef | d283f8c | 2017-05-10 18:20:11 +0200 | [diff] [blame^] | 84 | } |
| 85 | |
| 86 | @NonCPS |
| 87 | def _getRunningTriggeredTestsBuildNumbers(jobName, gerritChangeNumber, excludePatchsetNumber){ |
| 88 | return gerrit.getGerritTriggeredBuilds(jenkins.getJobRunningBuilds(jobName), gerritChangeNumber, excludePatchsetNumber) |
| 89 | .stream().map{it -> it.number}.collect(java.util.stream.Collectors.toList()) |
Jakub Josef | c5a223a | 2017-03-01 14:40:08 +0100 | [diff] [blame] | 90 | } |