Merge "Add pipeline and config file for testing groovy syntax"
diff --git a/build.gradle b/build.gradle
new file mode 100644
index 0000000..3847c12
--- /dev/null
+++ b/build.gradle
@@ -0,0 +1,25 @@
+apply plugin: 'groovy'
+apply plugin: 'codenarc'
+
+def jcenterRepo = System.getenv('ARTIFACTORY_URL') ?: 'https://artifactory.mcp.mirantis.net/jcenter'
+
+sourceSets {
+  main {
+    groovy {
+      srcDirs = ['src', 'vars']
+    }
+  }
+}
+
+compileGroovy.enabled = true
+
+repositories {
+  maven {
+    url jcenterRepo
+  }
+}
+
+codenarc {
+  configFile = new File('codenarcRules.groovy')
+  reportFormat = 'text'
+}
diff --git a/codenarcRules.groovy b/codenarcRules.groovy
new file mode 100644
index 0000000..17e8dac
--- /dev/null
+++ b/codenarcRules.groovy
@@ -0,0 +1,7 @@
+// File: codenarcRules.groovy
+
+ruleset {
+  ruleset('rulesets/basic.xml')
+  ruleset('rulesets/braces.xml')
+  ruleset('rulesets/imports.xml')
+}
diff --git a/test-groovy-pipeline.groovy b/test-groovy-pipeline.groovy
new file mode 100644
index 0000000..c63593f
--- /dev/null
+++ b/test-groovy-pipeline.groovy
@@ -0,0 +1,43 @@
+/**
+* Groovy code testing pipeline
+* CREDENTIALS_ID - gerrit credentials id
+* GRADLE_IMAGE - gradle image name
+* GRADLE_CMD - command(s) for gradle
+*
+**/
+
+gerrit = new com.mirantis.mk.Gerrit()
+common = new com.mirantis.mk.Common()
+
+node("docker"){
+    try {
+        stage ('Checkout source code'){
+            gerrit.gerritPatchsetCheckout ([
+              credentialsId : CREDENTIALS_ID,
+              withWipeOut : true
+            ])
+        }
+        stage ('Run Codenarc tests'){
+            def workspace = common.getWorkspace()
+            def gradle_report = sh (script: "docker run --rm -v ${workspace}:/usr/bin/app:rw ${GRADLE_IMAGE} ${GRADLE_CMD}",
+                                    returnStdout: true).trim()
+            // Compilation failure doesn't fail the build
+            // Check gradle output explicitly
+            common.infoMsg(gradle_report)
+            if ( gradle_report =~ /Compilation failed/ ) {
+                throw new Exception("COMPILATION FAILED!")
+            }
+        }
+
+    } catch (Throwable e) {
+        currentBuild.result = 'FAILURE'
+        def errLog = readFile('build/reports/codenarc/main.txt')
+        if(errLog){
+            print "Error log: ${errLog}"
+        }
+        throw e
+    } finally {
+        // send notification
+        common.sendNotification(currentBuild.result, "" ,["slack"])
+    }
+}