Publish Karma unit tests in Jenkins Publish Karma unit tests in Jenkins jenkins jenkins

Publish Karma unit tests in Jenkins


  • in order for Jenkins to be able to parse karma test results they must be published in the Junit XML format, the plugin that does that is karma-junit-reporter
  • junit test results (outputFile in the karma configuration file) must be stored in target/surefire-reports/TESTS-TestSuite.xml


    reporters        : ['progress', 'junit', 'coverage'],    port             : 9876,    colors           : true,    logLevel         : config.LOG_INFO,    // don't watch for file change    autoWatch        : false,    // only runs on headless browser    browsers         : ['PhantomJS'],    // just run one time    singleRun        : true,    // remove `karma-chrome-launcher` because we will be running on PhantomJS    // browser on Jenkins    plugins          : [        'karma-jasmine',        'karma-phantomjs-launcher',        'karma-junit-reporter',        'karma-coverage',        'karma-jenkins-reporter'    ],    // changes type to `cobertura`    coverageReporter : {        type : 'cobertura',        dir  : 'target/coverage-reports/'    },    // saves report at `target/surefire-reports/TEST-*.xml` because Jenkins    // looks for this location and file prefix by default.    junitReporter    : {        outputDir : 'target/surefire-reports/'    }


Old post, but top result in Google.

  1. Configure karma.conf.js to use 'karma-junit-reporter' and report to outputDir = 'target/karma-reports/'
  2. In your pom.xml, give the test execution step an execution/id like 'karmaTests'
  3. In your pom.xml, set a property jenkins.karmaTest.reportsDirectory = target/karma-reports

Full examples are on this blog post.