Jenkins – Jacoco coverage in Jenkins Pipeline

groovyjacocoJenkinsjenkins-plugins

Can anyone suggest if there is a way to execute Jacoco in a Jenkins Pipeline? I have downloaded the plugin but I do not get the option for Jacoco in the 'Pipeline Syntax', which is the Pipeline script help .

Referred this URL: https://wiki.jenkins-ci.org/display/JENKINS/JaCoCo+Plugin
which has no information for a jenkins jacoco pipeline

Best Answer

The jacoco pipeline step configuration uses this format:

step([$class: 'JacocoPublisher', 
      execPattern: 'target/*.exec',
      classPattern: 'target/classes',
      sourcePattern: 'src/main/java',
      exclusionPattern: 'src/test*'
])

Or with a simpler syntax for declarative pipeline:

jacoco( 
      execPattern: 'target/*.exec',
      classPattern: 'target/classes',
      sourcePattern: 'src/main/java',
      exclusionPattern: 'src/test*'
)

You can find more options in the JaCoCo Pipeline Steps Reference