MushyPeas MushyPeas - 3 years ago 244
Groovy Question

Compile groovy project and run JUnit tests via Jenkins

I googled for ages now and I give up, the buzz word Groovy + Jenkins is bringing up so many false flags...

I have a Groovy project I developed in IntelliJ, it contains also a JUnit.groovy with unit tests. Now this is a script for SoapUI, no need for Maven, Ant nor Grails, but I would like to be able to compile those files on Jenkins and run the unit tests after. Is it possible to build and test those files on Jenkins? So far all solutions seem to be me manually running groovyc (commited with my repository) and then running JUnit on the JUnit.class.

So before I start to dig deeper and write a Maven, Grails or Ant file, is there another way that does not involve me pushing the GroovySDK on my git? Or is there may be a simple build script, not involving 20 libraries and steps that would build the groovy sources and run the JUnit tests :) ?

I'm new to Jenkins obviously ;), thanks for your input.


  • So for all as newbie as me, what was required? First I changed my local source code to a gradle project (remember to activate AutoImport in IntelliJ) and also activate the creation of the JUnit xml and since I do not use Maven and the system is "offline" we have the libs in git anyway so my

    version '2.5-SNAPSHOT'
    apply plugin: 'groovy'
    dependencies {
    compile fileTree(dir: '../Library', include: ['*.jar'])
    test {
    reports {
    junitXml.enabled = true
    html.enabled = true
    sourceCompatibility = 1.8

  • set up gradle wrapper for the project via
    gradle wrapper
    for the

  • then I added a
    in my git-
    so my Jenkins is triggered upon commit via
    curl http://jenkins:8080/git/notifyCommit?url=https://git.git&branches=dev

  • finally set up a pipeline on jenkins:


    node {
    stage('Checkout') {
    git branch: 'dev', credentialsId: 'youwish', url: 'https://git.git'

    stage('Build') {
    dir('./Modules') {

    stage('UnitTest') {
    dir('./Modules') {
    junit '/build/test-results/**/TEST-*.xml'

    stage('IntegrationTest') {
    stage('CodeTableDownload') {
    dir('./SoapUi') {
    bat 'AutoRun.bat'
    junit '/results/**/*-JUNIT.xml'

    def gradle(command) {
    bat "./gradlew.bat $command"

Answer Source

There's a Groovy plugin for Jenkins that will let you execute Groovy scripts on Jenkins.

But, why not let something like Gradle do the build and run the test for you? A minimal Gradle build file for Groovy that will do both is:

apply plugin: 'groovy'

repositories {

dependencies {
    compile 'org.codehaus.groovy:groovy-all:2.4.12'
    testCompile 'junit:junit:4.12'

You don't have to commit the GDK, just declare a dependency.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download