blob: 65fce27ceb77ddb0a231401833dbb5af0a3c04bc [file] [log] [blame]
Filip Pytlounfcce97c2017-03-07 14:06:07 +01001def gerrit = new com.mirantis.mk.Gerrit()
Filip Pytloun6a057302017-03-07 16:33:30 +01002def common = new com.mirantis.mk.Common()
Filip Pytloun19376a82017-03-07 12:29:00 +01003
Filip Pytlounfcce97c2017-03-07 14:06:07 +01004def gerritCredentials
5try {
6 gerritCredentials = CREDENTIALS_ID
7} catch (MissingPropertyException e) {
8 gerritCredentials = "gerrit"
9}
10
Jakub Josef4612c5d2017-03-30 16:04:26 +020011def gerritRef
12try {
13 gerritRef = GERRIT_REFSPEC
14} catch (MissingPropertyException e) {
15 gerritRef = null
16}
17
18def defaultGitRef, defaultGitUrl
19try {
20 defaultGitRef = DEFAULT_GIT_REF
21 defaultGitUrl = DEFAULT_GIT_URL
22} catch (MissingPropertyException e) {
23 defaultGitRef = null
24 defaultGitUrl = null
25}
26def checkouted = false
27
Filip Pytlounfcce97c2017-03-07 14:06:07 +010028try {
29 stage("Checkout") {
30 node() {
Jakub Josef4612c5d2017-03-30 16:04:26 +020031 if (gerritRef) {
32 // job is triggered by Gerrit
33 checkouted = gerrit.gerritPatchsetCheckout ([
34 credentialsId : gerritCredentials
35 ])
36 // change defaultGit variables if job triggered from Gerrit
Jakub Josef63326772017-03-30 16:38:11 +020037 defaultGitUrl = "${GERRIT_SCHEME}://${GERRIT_NAME}@${GERRIT_HOST}:${GERRIT_PORT}/${GERRIT_PROJECT}"
Jakub Josef4612c5d2017-03-30 16:04:26 +020038 } else if(defaultGitRef && defaultGitUrl) {
39 checkouted = gerrit.gerritPatchsetCheckout(defaultGitUrl, defaultGitRef, "HEAD", gerritCredentials)
40 }
Filip Pytloun840a0842017-03-07 13:54:23 +010041 }
Filip Pytloun19376a82017-03-07 12:29:00 +010042 }
Filip Pytlounfcce97c2017-03-07 14:06:07 +010043
44 stage("Test") {
Jakub Josef4612c5d2017-03-30 16:04:26 +020045 if(checkouted){
46 def branches = [:]
47 def testModels = TEST_MODELS.split(',')
48 for (int i = 0; i < testModels.size(); i++) {
49 def cluster = testModels[i]
Jakub Josefb3f570b2017-03-30 17:02:16 +020050 def clusterGitUrl = defaultGitUrl.substring(0, defaultGitUrl.lastIndexOf("/") + 1) + cluster
Jakub Josef4612c5d2017-03-30 16:04:26 +020051 branches["${cluster}"] = {
52 build job: "test-salt-model-${cluster}", parameters: [
Jakub Josefb3f570b2017-03-30 17:02:16 +020053 [$class: 'StringParameterValue', name: 'DEFAULT_GIT_URL', value: clusterGitUrl],
Jakub Josef7818a932017-03-30 17:10:38 +020054 [$class: 'StringParameterValue', name: 'DEFAULT_GIT_REF', value: "HEAD"]
Jakub Josef4612c5d2017-03-30 16:04:26 +020055 ]
56 }
57 }
58 parallel branches
59 }else{
Jakub Josef5ce6a362017-03-31 13:41:17 +020060 throw new Exception("Cannot checkout gerrit patchset, GERRIT_REFSPEC and DEFAULT_GIT_REF is null")
Filip Pytlounfcce97c2017-03-07 14:06:07 +010061 }
Filip Pytlounfcce97c2017-03-07 14:06:07 +010062 }
63} catch (Throwable e) {
64 // If there was an error or exception thrown, the build failed
65 currentBuild.result = "FAILURE"
66 throw e
67} finally {
68 common.sendNotification(currentBuild.result,"",["slack"])
Filip Pytloun19376a82017-03-07 12:29:00 +010069}