验证Jenkins管道中Angular应用程序的覆盖率低

时间:2019-04-04 07:43:07

标签: angular jenkins jenkins-pipeline angular-test lcov

当我们想验证Java应用程序的代码覆盖率时,我们使用jacoco生成一个.exec文件,并运行Jenkins jacoco步骤以执行验证阈值,例如:

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

我想对从Jenkins管道构建的Angular应用程序执行相同的操作,如果不满足指定的阈值,将强制构建失败。

在管道阶段,我执行Angular测试:

sh "ng test --code-coverage"

这会在coverage/lcov.info中生成代码覆盖率lcov报告

我现在如何确认承保范围?我可以用Jenkins的某个步骤等效于jacoco()吗?

1 个答案:

答案 0 :(得分:0)

junit步骤应捕获这些内容。

这是一个例子

Jenkinsfile

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

纱线

{
  "test:ci": "ng test --config karma.conf.ci.js --code-coverage --progress=false"
}