code-coverage-api-plugin
code-coverage-api-plugin copied to clipboard
Plugin creates files & folders outside the build directory
Jenkins and plugins versions report
Environment
Paste the output here
What Operating System are you using (both controller, and any agents involved in the problem)?
RHEL8
Reproduction steps
I have the following in my Jenkinsfile as part of a Test stage that runs unit tests and generates a JaCoCo coverage report:
post {
success {
// https://github.com/jenkinsci/code-coverage-api-plugin#readme
recordCoverage(
tools: [[parser: 'JACOCO', pattern: '**/jacoco/test/jacocoTestReport.xml']],
id: 'jacoco',
name: 'JaCoCo Coverage',
sourceCodeRetention: 'EVERY_BUILD',
qualityGates: [
[threshold: 60.0, metric: 'LINE', baseline: 'PROJECT', unstable: true],
[threshold: 60.0, metric: 'BRANCH', baseline: 'PROJECT', unstable: true]
]
)
}
}
When doing release builds, the builds are failing, because the release plugin finds untracked (from a git perspective) files in the workspace. While reviewing the workspace in Jenkins after the failed build, I discovered (and then confirmed by searching the plugin project's source code) that the plugin is creating a coverage-sources.zip at the top level of the workspace.
From plugin/src/main/java/io/jenkins/plugins/coverage/metrics/source/SourceCodeFacade.java
/** Toplevel directory in the build folder of the controller that contains the zipped source files. */
--
static final String COVERAGE_SOURCES_DIRECTORY = "coverage-sources";
As an aside, the string "coverage-sources" seems to be repeated in four places in the source code, one of which is an inline string.
Expected Results
I would expect the plugin to either delete any files & folders it creates before it finishes or to put those files & folders inside the build directory. If the plugin would not be able to determine the location of the build directory, there should be a means of defining a temporary files location in the plugin's configuration.
Actual Results
The plugin's temporary files and folders appear to not have been deleted, and that is causing problems for a release plugin that runs in a subsequent stage.
Anything else?
Unrelated to my issue, I wanted to take a second to thank the developers who work on this project. We upgraded to a new version of Jenkins in the last couple of weeks and have just now been able to make use of this plugin. The visualizations and quality gates are very useful features, and, overall, this is a very nice upgrade from the JaCoCo plugin we were previously using.
Well, the workspace is exactly the place to write such information to 😄
Interested in providing a PR that uses a temp folder instead?