Filip Pytloun | fcce97c | 2017-03-07 14:06:07 +0100 | [diff] [blame] | 1 | def gerrit = new com.mirantis.mk.Gerrit() |
Filip Pytloun | 6a05730 | 2017-03-07 16:33:30 +0100 | [diff] [blame] | 2 | def common = new com.mirantis.mk.Common() |
Filip Pytloun | 19376a8 | 2017-03-07 12:29:00 +0100 | [diff] [blame] | 3 | |
Filip Pytloun | fcce97c | 2017-03-07 14:06:07 +0100 | [diff] [blame] | 4 | def gerritCredentials |
| 5 | try { |
| 6 | gerritCredentials = CREDENTIALS_ID |
| 7 | } catch (MissingPropertyException e) { |
| 8 | gerritCredentials = "gerrit" |
| 9 | } |
| 10 | |
Jakub Josef | 4612c5d | 2017-03-30 16:04:26 +0200 | [diff] [blame] | 11 | def gerritRef |
| 12 | try { |
| 13 | gerritRef = GERRIT_REFSPEC |
| 14 | } catch (MissingPropertyException e) { |
| 15 | gerritRef = null |
| 16 | } |
| 17 | |
| 18 | def defaultGitRef, defaultGitUrl |
| 19 | try { |
| 20 | defaultGitRef = DEFAULT_GIT_REF |
| 21 | defaultGitUrl = DEFAULT_GIT_URL |
| 22 | } catch (MissingPropertyException e) { |
| 23 | defaultGitRef = null |
| 24 | defaultGitUrl = null |
| 25 | } |
| 26 | def checkouted = false |
Jakub Josef | fcb615e | 2017-04-10 14:34:40 +0200 | [diff] [blame] | 27 | def merged = false |
chnyda | d66d6fa | 2017-06-22 09:34:43 +0200 | [diff] [blame] | 28 | def systemRefspec = "HEAD" |
chnyda | 708781e | 2017-10-02 15:40:07 +0200 | [diff] [blame^] | 29 | node() { |
| 30 | try { |
| 31 | stage("Checkout") { |
Jakub Josef | 4612c5d | 2017-03-30 16:04:26 +0200 | [diff] [blame] | 32 | if (gerritRef) { |
| 33 | // job is triggered by Gerrit |
Jakub Josef | fcb615e | 2017-04-10 14:34:40 +0200 | [diff] [blame] | 34 | // test if change aren't already merged |
Jakub Josef | 64045e9 | 2017-04-10 17:01:59 +0200 | [diff] [blame] | 35 | def gerritChange = gerrit.getGerritChange(GERRIT_NAME, GERRIT_HOST, GERRIT_CHANGE_NUMBER, gerritCredentials) |
Jakub Josef | fcb615e | 2017-04-10 14:34:40 +0200 | [diff] [blame] | 36 | merged = gerritChange.status == "MERGED" |
| 37 | if(!merged){ |
| 38 | checkouted = gerrit.gerritPatchsetCheckout ([ |
| 39 | credentialsId : gerritCredentials |
| 40 | ]) |
chnyda | d66d6fa | 2017-06-22 09:34:43 +0200 | [diff] [blame] | 41 | systemRefspec = GERRIT_REFSPEC |
Jakub Josef | fcb615e | 2017-04-10 14:34:40 +0200 | [diff] [blame] | 42 | } |
Jakub Josef | 4612c5d | 2017-03-30 16:04:26 +0200 | [diff] [blame] | 43 | // change defaultGit variables if job triggered from Gerrit |
Jakub Josef | 6332677 | 2017-03-30 16:38:11 +0200 | [diff] [blame] | 44 | defaultGitUrl = "${GERRIT_SCHEME}://${GERRIT_NAME}@${GERRIT_HOST}:${GERRIT_PORT}/${GERRIT_PROJECT}" |
Jakub Josef | 4612c5d | 2017-03-30 16:04:26 +0200 | [diff] [blame] | 45 | } else if(defaultGitRef && defaultGitUrl) { |
| 46 | checkouted = gerrit.gerritPatchsetCheckout(defaultGitUrl, defaultGitRef, "HEAD", gerritCredentials) |
| 47 | } |
Filip Pytloun | 840a084 | 2017-03-07 13:54:23 +0100 | [diff] [blame] | 48 | } |
Filip Pytloun | fcce97c | 2017-03-07 14:06:07 +0100 | [diff] [blame] | 49 | |
chnyda | 708781e | 2017-10-02 15:40:07 +0200 | [diff] [blame^] | 50 | stage("Test") { |
| 51 | if(merged){ |
| 52 | common.successMsg("Gerrit change is already merged, no need to test them") |
Jakub Josef | fcb615e | 2017-04-10 14:34:40 +0200 | [diff] [blame] | 53 | }else{ |
chnyda | 708781e | 2017-10-02 15:40:07 +0200 | [diff] [blame^] | 54 | 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 | |
| 61 | def branches = [:] |
| 62 | def testModels = documentationOnly ? [] : TEST_MODELS.split(',') |
| 63 | for (int i = 0; i < testModels.size(); i++) { |
| 64 | def cluster = testModels[i] |
| 65 | def clusterGitUrl = defaultGitUrl.substring(0, defaultGitUrl.lastIndexOf("/") + 1) + cluster |
| 66 | branches["${cluster}"] = { |
| 67 | build job: "test-salt-model-${cluster}", parameters: [ |
| 68 | [$class: 'StringParameterValue', name: 'DEFAULT_GIT_URL', value: clusterGitUrl], |
| 69 | [$class: 'StringParameterValue', name: 'DEFAULT_GIT_REF', value: "HEAD"], |
| 70 | [$class: 'StringParameterValue', name: 'SYSTEM_GIT_URL', value: defaultGitUrl], |
| 71 | [$class: 'StringParameterValue', name: 'SYSTEM_GIT_REF', value: systemRefspec] |
| 72 | ] |
| 73 | } |
| 74 | } |
| 75 | parallel branches |
| 76 | }else{ |
| 77 | throw new Exception("Cannot checkout gerrit patchset, GERRIT_REFSPEC and DEFAULT_GIT_REF is null") |
| 78 | } |
Jakub Josef | fcb615e | 2017-04-10 14:34:40 +0200 | [diff] [blame] | 79 | } |
Filip Pytloun | fcce97c | 2017-03-07 14:06:07 +0100 | [diff] [blame] | 80 | } |
chnyda | 708781e | 2017-10-02 15:40:07 +0200 | [diff] [blame^] | 81 | } catch (Throwable e) { |
| 82 | // If there was an error or exception thrown, the build failed |
| 83 | currentBuild.result = "FAILURE" |
| 84 | currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message |
| 85 | throw e |
| 86 | } finally { |
| 87 | common.sendNotification(currentBuild.result,"",["slack"]) |
Filip Pytloun | fcce97c | 2017-03-07 14:06:07 +0100 | [diff] [blame] | 88 | } |
Filip Pytloun | 19376a8 | 2017-03-07 12:29:00 +0100 | [diff] [blame] | 89 | } |