codependent
codependent

Reputation: 24452

Verify low coverage of an Angular application in a Jenkins pipeline

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?

Upvotes: 1

Views: 1191

Answers (1)

hakamairi
hakamairi

Reputation: 4678

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"
}

Upvotes: 1

Related Questions