blob: 6e3cb1144cd06abe20505b643a941c39079fbfe0 [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"
chnyda708781e2017-10-02 15:40:07 +020029node() {
30 try {
31 stage("Checkout") {
Jakub Josef4612c5d2017-03-30 16:04:26 +020032 if (gerritRef) {
33 // job is triggered by Gerrit
Jakub Joseffcb615e2017-04-10 14:34:40 +020034 // test if change aren't already merged
Jakub Josef64045e92017-04-10 17:01:59 +020035 def gerritChange = gerrit.getGerritChange(GERRIT_NAME, GERRIT_HOST, GERRIT_CHANGE_NUMBER, gerritCredentials)
Jakub Joseffcb615e2017-04-10 14:34:40 +020036 merged = gerritChange.status == "MERGED"
37 if(!merged){
38 checkouted = gerrit.gerritPatchsetCheckout ([
39 credentialsId : gerritCredentials
40 ])
chnydad66d6fa2017-06-22 09:34:43 +020041 systemRefspec = GERRIT_REFSPEC
Jakub Joseffcb615e2017-04-10 14:34:40 +020042 }
Jakub Josef4612c5d2017-03-30 16:04:26 +020043 // change defaultGit variables if job triggered from Gerrit
Jakub Josef63326772017-03-30 16:38:11 +020044 defaultGitUrl = "${GERRIT_SCHEME}://${GERRIT_NAME}@${GERRIT_HOST}:${GERRIT_PORT}/${GERRIT_PROJECT}"
Jakub Josef4612c5d2017-03-30 16:04:26 +020045 } else if(defaultGitRef && defaultGitUrl) {
46 checkouted = gerrit.gerritPatchsetCheckout(defaultGitUrl, defaultGitRef, "HEAD", gerritCredentials)
47 }
Filip Pytloun840a0842017-03-07 13:54:23 +010048 }
Filip Pytlounfcce97c2017-03-07 14:06:07 +010049
chnyda708781e2017-10-02 15:40:07 +020050 stage("Test") {
51 if(merged){
52 common.successMsg("Gerrit change is already merged, no need to test them")
Jakub Joseffcb615e2017-04-10 14:34:40 +020053 }else{
chnyda708781e2017-10-02 15:40:07 +020054 if(checkouted){
55
56 def documentationOnly = false
57 if (gerritRef) {
58 documentationOnly = sh(script: "git diff-tree --no-commit-id --name-only -r HEAD | grep -v .releasenotes", returnStatus: true) == 1
59 }
60
chnyda9bb38b22017-11-13 13:55:57 +010061 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'))\" \\;")
62
chnyda708781e2017-10-02 15:40:07 +020063 def branches = [:]
64 def testModels = documentationOnly ? [] : TEST_MODELS.split(',')
chnyda6f78a9d2017-12-19 11:34:26 +010065 for (int i = 0; i < testModels.size(); i++) {
66 def cluster = testModels[i]
67 def clusterGitUrl = defaultGitUrl.substring(0, defaultGitUrl.lastIndexOf("/") + 1) + cluster
68 branches["${cluster}"] = {
69 build job: "test-salt-model-${cluster}", parameters: [
70 [$class: 'StringParameterValue', name: 'DEFAULT_GIT_URL', value: clusterGitUrl],
71 [$class: 'StringParameterValue', name: 'DEFAULT_GIT_REF', value: "HEAD"],
72 [$class: 'StringParameterValue', name: 'SYSTEM_GIT_URL', value: defaultGitUrl],
73 [$class: 'StringParameterValue', name: 'SYSTEM_GIT_REF', value: systemRefspec]
74 ]
chnyda708781e2017-10-02 15:40:07 +020075 }
chnyda6f78a9d2017-12-19 11:34:26 +010076 }
77 branches["cookiecutter"] = {
78 build job: "test-mk-cookiecutter-templates", parameters: [
79 [$class: 'StringParameterValue', name: 'SYSTEM_GIT_URL', value: defaultGitUrl],
80 [$class: 'StringParameterValue', name: 'SYSTEM_GIT_REF', value: systemRefspec]
81 ]
82 }
chnyda708781e2017-10-02 15:40:07 +020083 parallel branches
84 }else{
85 throw new Exception("Cannot checkout gerrit patchset, GERRIT_REFSPEC and DEFAULT_GIT_REF is null")
86 }
Jakub Joseffcb615e2017-04-10 14:34:40 +020087 }
Filip Pytlounfcce97c2017-03-07 14:06:07 +010088 }
chnyda708781e2017-10-02 15:40:07 +020089 } catch (Throwable e) {
90 // If there was an error or exception thrown, the build failed
91 currentBuild.result = "FAILURE"
92 currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message
93 throw e
94 } finally {
95 common.sendNotification(currentBuild.result,"",["slack"])
Filip Pytlounfcce97c2017-03-07 14:06:07 +010096 }
Filip Pytloun19376a82017-03-07 12:29:00 +010097}