blob: 6d12ec6dbbd212097949fc6713e8789fd39f39c0 [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
6 */
Jakub Josefc5a223a2017-03-01 14:40:08 +01007def common = new com.mirantis.mk.Common()
8def gerrit = new com.mirantis.mk.Gerrit()
Jakub Joseff64c6392017-05-03 13:18:25 +02009def ruby = new com.mirantis.mk.Ruby()
Jakub Josefd283f8c2017-05-10 18:20:11 +020010def jenkinsUtils = new com.mirantis.mk.JenkinsUtils()
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
28def checkouted = false;
29
Jakub Josef52baaa42017-05-04 12:20:54 +020030node("python&&docker") {
Jakub Josefc5a223a2017-03-01 14:40:08 +010031 try{
Tomáš Kukrál843e7d92017-05-11 11:05:24 +020032 //stage("stop old tests"){
33 // if (gerritRef) {
34 // def runningTestBuildNums = _getRunningTriggeredTestsBuildNumbers(env["JOB_NAME"], GERRIT_CHANGE_NUMBER, GERRIT_PATCHSET_NUMBER)
35 // for(int i=0; i<runningTestBuildNums.size(); i++){
36 // common.infoMsg("Old test with run number ${runningTestBuildNums[i]} found, stopping")
37 // Jenkins.instance.getItemByFullName(env["JOB_NAME"]).getBuildByNumber(runningTestBuildNums[i]).finish(hudson.model.Result.ABORTED, new java.io.IOException("Aborting build"));
38 // }
39 // }
40 //}
Jakub Josefc5a223a2017-03-01 14:40:08 +010041 stage("checkout") {
Jakub Josef83379312017-03-29 18:12:34 +020042 if (gerritRef) {
43 // job is triggered by Gerrit
44 checkouted = gerrit.gerritPatchsetCheckout ([
Jakub Josefc5a223a2017-03-01 14:40:08 +010045 credentialsId : CREDENTIALS_ID
Jakub Josef83379312017-03-29 18:12:34 +020046 ])
47 } else if(defaultGitRef && defaultGitUrl) {
Jakub Josefe1407ac2017-03-30 14:10:19 +020048 checkouted = gerrit.gerritPatchsetCheckout(defaultGitUrl, defaultGitRef, "HEAD", CREDENTIALS_ID)
Jakub Josef83379312017-03-29 18:12:34 +020049 }
50 if(!checkouted){
Jakub Josef5ce6a362017-03-31 13:41:17 +020051 throw new Exception("Cannot checkout gerrit patchset, GERRIT_REFSPEC and DEFAULT_GIT_REF is null")
Jakub Josef83379312017-03-29 18:12:34 +020052 }
Jakub Josefc5a223a2017-03-01 14:40:08 +010053 }
54 stage("test") {
Jakub Josef83379312017-03-29 18:12:34 +020055 if(checkouted){
56 wrap([$class: 'AnsiColorBuildWrapper']) {
57 sh("make clean")
58 sh("[ $SALT_VERSION != 'latest' ] || export SALT_VERSION=''; make test")
59 }
Jakub Josefc5a223a2017-03-01 14:40:08 +010060 }
61 }
Jakub Joseff64c6392017-05-03 13:18:25 +020062 stage("kitchen") {
63 if (fileExists(".kitchen.yml")) {
Jakub Josef52baaa42017-05-04 12:20:54 +020064 common.infoMsg(".kitchen.yml found, running kitchen tests")
Jakub Joseff64c6392017-05-03 13:18:25 +020065 ruby.ensureRubyEnv()
66 ruby.installKitchen()
67 wrap([$class: 'AnsiColorBuildWrapper']) {
68 ruby.runKitchenTests()
69 }
70 } else {
71 common.infoMsg(".kitchen.yml not found")
72 }
73 }
Jakub Josefc5a223a2017-03-01 14:40:08 +010074 } catch (Throwable e) {
75 // If there was an error or exception thrown, the build failed
76 currentBuild.result = "FAILURE"
77 throw e
78 } finally {
Jakub Josef52baaa42017-05-04 12:20:54 +020079 if(currentBuild.result == "FAILURE" && fileExists(".kitchen/logs/kitchen.log")){
Jakub Joseff96ebc52017-05-04 12:37:19 +020080 common.errorMsg("----------------KITCHEN LOG:---------------")
Jakub Josef52baaa42017-05-04 12:20:54 +020081 println readFile(".kitchen/logs/kitchen.log")
82 }
Jakub Josefc5a223a2017-03-01 14:40:08 +010083 common.sendNotification(currentBuild.result,"",["slack"])
84 }
Jakub Josefd283f8c2017-05-10 18:20:11 +020085}
86
87@NonCPS
88def _getRunningTriggeredTestsBuildNumbers(jobName, gerritChangeNumber, excludePatchsetNumber){
Jakub Josef3f727f62017-05-10 19:08:44 +020089 return gerrit.getGerritTriggeredBuilds(jenkinsUtils.getJobRunningBuilds(jobName), gerritChangeNumber, excludePatchsetNumber)
Jakub Josefd283f8c2017-05-10 18:20:11 +020090 .stream().map{it -> it.number}.collect(java.util.stream.Collectors.toList())
Tomáš Kukrál8d2d6a32017-05-11 10:18:33 +020091}