blob: fa1673964444a7fe6c7744c1946f0348013fb260 [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
Jakub Joseffcb615e2017-04-10 14:34:40 +020027def merged = false
chnydad66d6fa2017-06-22 09:34:43 +020028def systemRefspec = "HEAD"
Vasyl Saienko6c3cd6b2018-06-26 14:02:51 +030029def formulasRevision = 'testing'
Jakub Josefa63f9862018-01-11 17:58:38 +010030timeout(time: 12, unit: 'HOURS') {
31 node() {
32 try {
33 stage("Checkout") {
34 if (gerritRef) {
35 // job is triggered by Gerrit
36 // test if change aren't already merged
37 def gerritChange = gerrit.getGerritChange(GERRIT_NAME, GERRIT_HOST, GERRIT_CHANGE_NUMBER, gerritCredentials)
38 merged = gerritChange.status == "MERGED"
39 if(!merged){
40 checkouted = gerrit.gerritPatchsetCheckout ([
41 credentialsId : gerritCredentials
42 ])
43 systemRefspec = GERRIT_REFSPEC
chnyda708781e2017-10-02 15:40:07 +020044 }
Jakub Josefa63f9862018-01-11 17:58:38 +010045 // change defaultGit variables if job triggered from Gerrit
46 defaultGitUrl = "${GERRIT_SCHEME}://${GERRIT_NAME}@${GERRIT_HOST}:${GERRIT_PORT}/${GERRIT_PROJECT}"
47 } else if(defaultGitRef && defaultGitUrl) {
48 checkouted = gerrit.gerritPatchsetCheckout(defaultGitUrl, defaultGitRef, "HEAD", gerritCredentials)
49 }
50 }
chnyda708781e2017-10-02 15:40:07 +020051
Jakub Josefa63f9862018-01-11 17:58:38 +010052 stage("Test") {
53 if(merged){
54 common.successMsg("Gerrit change is already merged, no need to test them")
55 }else{
56 if(checkouted){
chnyda9bb38b22017-11-13 13:55:57 +010057
Jakub Josefa63f9862018-01-11 17:58:38 +010058 def documentationOnly = false
59 if (gerritRef) {
60 documentationOnly = sh(script: "git diff-tree --no-commit-id --name-only -r HEAD | grep -v .releasenotes", returnStatus: true) == 1
61 }
62
63 sh("git diff-tree --no-commit-id --diff-filter=d --name-only -r HEAD | grep .yml | xargs -I {} python -c \"import yaml; yaml.load(open('{}', 'r'))\" \\;")
64
65 def branches = [:]
66 def testModels = documentationOnly ? [] : TEST_MODELS.split(',')
67 for (int i = 0; i < testModels.size(); i++) {
68 def cluster = testModels[i]
69 def clusterGitUrl = defaultGitUrl.substring(0, defaultGitUrl.lastIndexOf("/") + 1) + cluster
70 branches["${cluster}"] = {
71 build job: "test-salt-model-${cluster}", parameters: [
72 [$class: 'StringParameterValue', name: 'DEFAULT_GIT_URL', value: clusterGitUrl],
73 [$class: 'StringParameterValue', name: 'DEFAULT_GIT_REF', value: "HEAD"],
74 [$class: 'StringParameterValue', name: 'SYSTEM_GIT_URL', value: defaultGitUrl],
Vasyl Saienko6c3cd6b2018-06-26 14:02:51 +030075 [$class: 'StringParameterValue', name: 'SYSTEM_GIT_REF', value: systemRefspec],
76 [$class: 'StringParameterValue', name: 'FORMULAS_REVISION', value: formulasRevision],
Jakub Josefa63f9862018-01-11 17:58:38 +010077 ]
78 }
79 }
80 branches["cookiecutter"] = {
81 build job: "test-mk-cookiecutter-templates", parameters: [
chnyda6f78a9d2017-12-19 11:34:26 +010082 [$class: 'StringParameterValue', name: 'SYSTEM_GIT_URL', value: defaultGitUrl],
Vasyl Saienko6c3cd6b2018-06-26 14:02:51 +030083 [$class: 'StringParameterValue', name: 'SYSTEM_GIT_REF', value: systemRefspec],
84 [$class: 'StringParameterValue', name: 'DISTRIB_REVISION', value: formulasRevision]
85
chnyda6f78a9d2017-12-19 11:34:26 +010086 ]
chnyda708781e2017-10-02 15:40:07 +020087 }
Jakub Josefa63f9862018-01-11 17:58:38 +010088 parallel branches
89 }else{
90 throw new Exception("Cannot checkout gerrit patchset, GERRIT_REFSPEC and DEFAULT_GIT_REF is null")
chnyda6f78a9d2017-12-19 11:34:26 +010091 }
chnyda708781e2017-10-02 15:40:07 +020092 }
Jakub Joseffcb615e2017-04-10 14:34:40 +020093 }
Jakub Josefa63f9862018-01-11 17:58:38 +010094 } catch (Throwable e) {
95 // If there was an error or exception thrown, the build failed
96 currentBuild.result = "FAILURE"
97 currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message
98 throw e
99 } finally {
100 common.sendNotification(currentBuild.result,"",["slack"])
Filip Pytlounfcce97c2017-03-07 14:06:07 +0100101 }
Filip Pytlounfcce97c2017-03-07 14:06:07 +0100102 }
Filip Pytloun19376a82017-03-07 12:29:00 +0100103}