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, |
| 17 | withWipeOut : true |
| 18 | ]) |
| 19 | } |
| 20 | stage ('Run Codenarc tests'){ |
| 21 | def workspace = common.getWorkspace() |
| 22 | def gradle_report = sh (script: "docker run --rm -v ${workspace}:/usr/bin/app:rw ${GRADLE_IMAGE} ${GRADLE_CMD}", |
| 23 | returnStdout: true).trim() |
| 24 | // Compilation failure doesn't fail the build |
| 25 | // Check gradle output explicitly |
| 26 | common.infoMsg(gradle_report) |
| 27 | if ( gradle_report =~ /Compilation failed/ ) { |
| 28 | throw new Exception("COMPILATION FAILED!") |
| 29 | } |
| 30 | } |
| 31 | |
| 32 | } catch (Throwable e) { |
| 33 | currentBuild.result = 'FAILURE' |
Jakub Josef | 97e0957 | 2017-03-22 13:59:02 +0100 | [diff] [blame^] | 34 | try{ |
| 35 | def errLog = readFile('build/reports/codenarc/main.txt') |
| 36 | if(errLog){ |
| 37 | common.errorMsg("Error log: ${errLog}") |
| 38 | } |
| 39 | }catch(ex){} |
Jakub Josef | d75c1d5 | 2017-03-15 18:06:03 +0100 | [diff] [blame] | 40 | throw e |
| 41 | } finally { |
| 42 | // send notification |
| 43 | common.sendNotification(currentBuild.result, "" ,["slack"]) |
| 44 | } |
| 45 | } |