| 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' | 
|  | 34 | def errLog = readFile('build/reports/codenarc/main.txt') | 
|  | 35 | if(errLog){ | 
|  | 36 | print "Error log: ${errLog}" | 
|  | 37 | } | 
|  | 38 | throw e | 
|  | 39 | } finally { | 
|  | 40 | // send notification | 
|  | 41 | common.sendNotification(currentBuild.result, "" ,["slack"]) | 
|  | 42 | } | 
|  | 43 | } |