Jakub Josef | d75c1d5 | 2017-03-15 18:06:03 +0100 | [diff] [blame] | 1 | /** |
| 2 | * Groovy code testing pipeline |
| 3 | * CREDENTIALS_ID - gerrit credentials id |
| 4 | * GRADLE_IMAGE - gradle image name |
| 5 | * GRADLE_CMD - command(s) for gradle |
| 6 | * |
| 7 | **/ |
| 8 | |
| 9 | gerrit = new com.mirantis.mk.Gerrit() |
| 10 | common = new com.mirantis.mk.Common() |
| 11 | |
| 12 | node("docker"){ |
| 13 | try { |
| 14 | stage ('Checkout source code'){ |
| 15 | gerrit.gerritPatchsetCheckout ([ |
| 16 | credentialsId : CREDENTIALS_ID, |
Jakub Josef | 575d50b | 2017-03-23 17:55:41 +0100 | [diff] [blame] | 17 | withWipeOut : true, |
| 18 | gerritRefSpec: GERRIT_REFSPEC, |
| 19 | gerritName: GERRIT_NAME, |
| 20 | gerritHost: GERRIT_HOST, |
| 21 | gerritPort: GERRIT_PORT, |
| 22 | gerritProject: GERRIT_PROJECT, |
| 23 | gerritBranch: GERRIT_BRANCH, |
Jakub Josef | d75c1d5 | 2017-03-15 18:06:03 +0100 | [diff] [blame] | 24 | ]) |
| 25 | } |
| 26 | stage ('Run Codenarc tests'){ |
| 27 | def workspace = common.getWorkspace() |
Jakub Josef | 1ee1e4a | 2017-03-23 12:36:25 +0100 | [diff] [blame] | 28 | def jenkinsUID = common.getJenkinsUid() |
| 29 | def jenkinsGID = common.getJenkinsGid() |
| 30 | def gradle_report = sh (script: "docker run --rm -v ${workspace}:/usr/bin/app:rw -u ${jenkinsUID}:${jenkinsGID} ${GRADLE_IMAGE} ${GRADLE_CMD}", returnStdout: true).trim() |
Jakub Josef | d75c1d5 | 2017-03-15 18:06:03 +0100 | [diff] [blame] | 31 | // Compilation failure doesn't fail the build |
| 32 | // Check gradle output explicitly |
| 33 | common.infoMsg(gradle_report) |
| 34 | if ( gradle_report =~ /Compilation failed/ ) { |
| 35 | throw new Exception("COMPILATION FAILED!") |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | } catch (Throwable e) { |
| 40 | currentBuild.result = 'FAILURE' |
Jakub Josef | 97e0957 | 2017-03-22 13:59:02 +0100 | [diff] [blame] | 41 | try{ |
| 42 | def errLog = readFile('build/reports/codenarc/main.txt') |
| 43 | if(errLog){ |
| 44 | common.errorMsg("Error log: ${errLog}") |
| 45 | } |
| 46 | }catch(ex){} |
Jakub Josef | d75c1d5 | 2017-03-15 18:06:03 +0100 | [diff] [blame] | 47 | throw e |
| 48 | } finally { |
| 49 | // send notification |
| 50 | common.sendNotification(currentBuild.result, "" ,["slack"]) |
| 51 | } |
| 52 | } |