1

When we want to verify the code coverage of a Java application we use jacoco to generate a .exec file and run a Jenkins jacoco step to enforce the validatio thresholds, e.g:

def classPattern = '**/target/classes'
def execPattern = '**/target/**.exec'
def sourcePattern = '**/src/main/java'

def coverageThreshold = 50

jacoco changeBuildStatus: true, classPattern: classPattern, maximumLineCoverage: "$coverageThreshold", minimumLineCoverage: "$coverageThreshold", execPattern: execPattern, sourcePattern: sourcePattern
if (currentBuild.result != 'SUCCESS') {
    error 'JaCoCo coverage failed'
}

I would like to do the same for an Angular application built from a Jenkins pipeline, forcing the build to fail if the specified threshold isn't met.

In a pipeline stage I execute the Angular tests:

sh "ng test --code-coverage"

This generates a code coverage lcov report in coverage/lcov.info

How can I verify the coverage now? Is there some Jenkins step equivalent to jacoco() I can use to do it?

codependent
  • 23,193
  • 31
  • 166
  • 308

1 Answers1

1

junit step should capture those.

Here's an example

Jenkinsfile

stage('Unit Test') {
  agent {
    docker 'circleci/node:9.3-stretch-browsers'
  }
  steps {
    unstash 'node_modules'
    sh 'yarn test:ci'
    junit 'reports/**/*.xml'
  }
}

Yarn

{
  "test:ci": "ng test --config karma.conf.ci.js --code-coverage --progress=false"
}
hakamairi
  • 4,464
  • 4
  • 30
  • 53
  • afaik junit step only captures test failures, but not code coverage like the jacoco step does – wotanii Aug 12 '21 at 08:08
  • 1
    Well now that I read it I'm not sure what I meant anymore. This answer might have not been valid at all. – hakamairi Aug 13 '21 at 11:08