Lars
Lars

Reputation: 340

Using Clover PHP and Checkstyle in Jenkinsfile

Inside my Freestyle Jenkins job I can add the Post-build actions to generate a code coverage report using the plugin Clover PHP and an analysis using Checkstyle plugin.

However, I like to use the Pipeline Jenkins job, because it has the stage view. With the Pipeline job I need to set up everything inside a Jenkinsfile. How do I include the Clover PHP and Checkstyle plugin function inside a Jenkinsfile? There is no documentation on their page.

Upvotes: 2

Views: 3761

Answers (4)

Brice LALU
Brice LALU

Reputation: 173

To complete other answers, Clover PHP dont have jenkins pipeline support... But you dont need this plugin, all you need is the Clover Plugin

One installed, then all you have to add in your jenkinsfile for your example, is:

step([
$class: 'CloverPublisher',
cloverReportDir: 'reports/coverage',
cloverReportFileName: 'coverage.xml',
healthyTarget: [methodCoverage: 70, conditionalCoverage: 80, statementCoverage: 80],
unhealthyTarget: [methodCoverage: 50, conditionalCoverage: 50, statementCoverage: 50],
failingTarget: [methodCoverage: 0, conditionalCoverage: 0, statementCoverage: 0]])

This what I use in my current project.

Upvotes: 4

Jon Skarpeteig
Jon Skarpeteig

Reputation: 4128

The snippet generator from Jenkins is a great resource for this.

Unfortunately, there's no native support for Clover PHP, but there is for Checkstyle:

checkstyle canRunOnFailed: true, defaultEncoding: '', healthy: '', pattern: 'build/logs/checkstyle.xml', unHealthy: ''

Upvotes: 1

Marcos Pagnucco
Marcos Pagnucco

Reputation: 341

After much tinkering I managed to run Checkstyle on pipeline like this:

stage ('Static code analysis') {
    sh "sudo phpcs --config-set ignore_warnings_on_exit 1 --report=checkstyle --report-file=checkstyle-result.xml -q /code"
    step([$class: 'hudson.plugins.checkstyle.CheckStylePublisher', pattern: 'checkstyle-*'])
}

The first step generates the report and the second calls the Checkstyle plugin to process the report. I have not used Clover PHP so can't help you with that.

Upvotes: 3

Mark Stosberg
Mark Stosberg

Reputation: 13381

Since both the things you want to integrate with have CLI interfaces, you can just call their CLIs using an sh action in the Jenkinsfile to call a shell command. Here's an example from the Clover PHP docs:

sh "phpunit --log-junit 'reports/unitreport.xml' --coverage-html 'reports/coverage' --coverage-clover 'reports/coverage/coverage.xml' test/"

The location for the Junit log will vary depending on where you put in your project. You must run a junit step before this runs.

Checkstyle also has a CLI that you can call in a similar way from an sh action in your Jenkinsfile.

As long as you archive the resulting HTML files with your build, you can read the resulting HTML files by navigating to them through the "Build Artifacts" link on the build page. An example URL structure might look like:

https://ci.example.com/job/develop/342/artifact/reports/coverage/index.html

For deeper integration, the tools may need explicit Jenkins Pipeline support.

Upvotes: 2

Related Questions