20 Jun 2012

Configure Hudson for CodeCoverage and CodeNarc

Grails, hudson 0 Comment

Get it working on local machine.

testing this on my machine.  configured nbos-grails-auth/grails-app/conf/BuildConfig.groovy to include both codecoverage plugin and codenarc plugin

    plugins {
      // Testing
      test ':code-coverage:1.2.5', {
        export = false
      }
      test ':codenarc:0.17', {
        export = false
      }
   ...
   }

run the tests

[09:24][vineeln@mob05:~/work/nbos-grails-auth(master)]$ grails test-app -coverage
....
| Cobertura Code Coverage Complete (view reports in: target/test-reports/cobertura)
Flushing results...
Flushing results done
Cobertura: Loaded information on 77 classes.
Cobertura: Saved information on 77 classes.

Open the actual test results target/test-reports/html/all.html

Open the coverage report target/test-reports/cobertura/index.html

now lets execute code syntax and standards validation

[09:36][vineeln@mob05:~/work/nbos-grails-auth(master)]$ grails codenarc
| Loading Grails 2.0.1
(nbos-grails-auth): Running with inline plugins...
| Compiling 106 source files

| Compiling 25 source files...
(nbos-grails-auth): Running with inline plugins...
Running CodeNarc ...
| Compiling 25 source files....
CodeNarc finished; report(s) generated: [target/CodeNarcReport.html]

opening the report target/CodeNarcReport.html

Configure Hudson

Configure Cobertura & Tests

Intstall Cobertura plugin

Configure Cobertura Converage plugin

Configure JUnit Publish Report

after couple of builds we should now be able to see the converage & test results on the build..

Configure Code Voilations / CodeNarc

install code violations plugin, “Jenkins -> Manage Jenkins -> Manage Plugins” check if its already installed, if not install it.

configure grails-app/conf/BuildConfig.groovy, made this conditional so that it will generate html output on local dev & as xml on hudson.

codenarc {
  reportType=(System.getProperty('build')) ? 'xml' : 'html';
}

configure build to generate code violations “grails codenarc”

configure post build to read the codenarc report

the build should now have the code violations report.

That’s it.  hope this was useful.