For the notifications center development (rNOTIF), we were happy with a Jenkins PHP template prepared by Sebastian Bergmann (phpunit), http://jenkins-php.org/, not maintained anymore.
The main feature we used were the phpunit tests, phpcs and the code coverage.
A lot of those components aren't maintained anymore at Jenkins level and marked as deprecated. A lot of them are now a part of the Jenkins Warnings Plugin:
"The Jenkins Next Generation Warnings plug-in replaces the whole Jenkins Static Analysis Suite. I.e. it makes the following Jenkins plugins obsolete: Android Lint, CheckStyle, Dry, FindBugs, PMD, Warnings, Static Analysis Utilities, Static Analysis Collector."
Meanwhile:
- some tools we use and consider important, like phan, aren't called in CI -> let's add them
- a declarative pipeline syntax exist
A new PHP template would so be helpful.
The expected format is a modern Jenkinsfile pipeline.
Plugins used in legacy template
Plugin | Role | Status | Alternative plan |
Checkstyle | processing PHP_CodeSniffer logfiles in Checkstyle format | deprecated | phpcs can be run without dedicated plugin, but it's also now a part of the Jenkins Warnings Plugin |
Clover PHP | processing PHPUnit's Clover XML logfile | OK | keep it to offer a test coverage dashboard |
Crap4J | processing PHPUnit's Crap4J XML logfile | OK | ? |
DRY | processing phpcpd logfiles in PMD-CPD format | deprecated | Now a part of the Jenkins Warnings Plugin |
HTML Publisher | publishing documentation generated by phpDox, for instance | OK | not needed |
JDepend | processing PHP_Depend logfiles in JDepend format | OK | ? |
Plot | processing phploc CSV output | OK | ? |
PMD | processing PHPMD logfiles in PMD format | deprecated | Now a part of the Jenkins Warnings Plugin |
Violations | processing various logfiles | deprecated | can be implemented by the Jenkins Warnings Plugin |
Warnings | processing PHP compiler warnings in the console log | deprecated | Superseded by the Jenkins Warnings Plugin |
xUnit | processing PHPUnit's JUnit XML logfile | OK | Keep, and migrate to pipelines |
Example of how to use the warnings plugin
There is an integrated mode where we can run through Maven a script pretty similar to the current XML we use to define jobs, collect results with scanForIssues and then publish them with publishIssues:
node { ... stage('Analysis') { def mvnHome = tool 'mvn-default' sh "${mvnHome}/bin/mvn --batch-mode -V -U -e checkstyle:checkstyle pmd:pmd pmd:cpd" def checkstyle = scanForIssues tool: checkStyle(pattern: '**/target/checkstyle-result.xml') publishIssues issues: [checkstyle] def pmd = scanForIssues tool: pmdParser(pattern: '**/target/pmd.xml') publishIssues issues: [pmd] def cpd = scanForIssues tool: cpd(pattern: '**/target/cpd.xml') publishIssues issues: [cpd] def maven = scanForIssues tool: mavenConsole() publishIssues issues: [maven] publishIssues id: 'analysis', name: 'All Issues', issues: [checkstyle, pmd], filters: [includePackage('io.jenkins.plugins.analysis.*')] } ... }
Example of how to use the xunit plugin
Declarative pipeline format:
pipeline { agent any stages { stage('Test'){ steps { sh "run_tests.bash" } } } post { always{ xunit ( thresholds: [ skipped(failureThreshold: '0'), failed(failureThreshold: '0') ], tools: [ BoostTest(pattern: 'boost/*.xml') ]) ) } } }
Example of how to use the HTML Publisher plugin
This plugin has some documented advanced syntax features.
Like we do for Rust, we can create a Documentation step with a sh call to phpDox, then something like:
publishHTML (target : [ allowMissing: false, alwaysLinkToLastBuild: false, keepAll: true, reportDir: 'build/api', reportFiles: 'index.html', reportName: 'API Documentation', reportTitles: 'API doc'])
(values based on current config.xml content)
Keep or discard build.xml?
Currently a build.xml file is included in each PHP project, as an ant script to call the different tools. This format is a popular alternative of Makefile in Java world.
We can keep it and call it through:
- sh "ant phabricator-build" for quick tests triggered by a new Phabricator revision in code review
- sh "ant" (without any target specified), for default suite of tests, triggered by new commits in main branch
This script will run the tests, all the static analysis tools, the documentation, populate the result files.
And then we can call the warnings plugin (see above).
Or we can supersede it by pure Jenkinsfile, like here.
A middle ground approach could also be:
- Keep build.xml for static analysis
- Move non static analysis stuff in Jenkinsfile (e.g. documentation)
The moved content would then be the content belonging to other steps.
That would have the benefit to allow the analysis to run fully without failing and to get a comprehensive report of what happens. I'd especially like if phpcs fails, it still runs phan (phan to add by the way somewhere, in build.xml or Jenkinsfile).