简体   繁体   中英

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, eg:

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM