jenkinsci / code-coverage-api-plugin

Deprecated Jenkins Code Coverage Plugin
https://plugins.jenkins.io/code-coverage-api/
MIT License
111 stars 77 forks source link

Plugin creates files & folders outside the build directory #733

Open prsice opened 1 year ago

prsice commented 1 year ago

Jenkins and plugins versions report

Environment ```text 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.

uhafner commented 1 year ago

Well, the workspace is exactly the place to write such information to 😄

Interested in providing a PR that uses a temp folder instead?

adijesori commented 4 days ago

Hi @prsice, We suffer from the same issue.

Did you able to solve this issue without .gitignore the zip file?

@uhafner As a suggestion, is it possible to delete the zip file once the plugin finished running?

stefan6419846 commented 4 days ago

As this plugin is deprecated, there probably will not be any such changes anymore. You should give the successor https://github.com/jenkinsci/coverage-plugin a try and report an issue there if the problem still persists.

uhafner commented 4 days ago

Hi @prsice, We suffer from the same issue.

Did you able to solve this issue without .gitignore the zip file?

@uhafner As a suggestion, is it possible to delete the zip file once the plugin finished running?

Both options are possible, yes. Interested in providing a PR for the coverage-plugin? It shouldn't be hard to change that part of the code. (As Stefan mentioned: please note that only the coverage plugin is supported anymore).

adijesori commented 4 days ago

Hi @prsice, We suffer from the same issue. Did you able to solve this issue without .gitignore the zip file? @uhafner As a suggestion, is it possible to delete the zip file once the plugin finished running?

Both options are possible, yes. Interested in providing a PR for the coverage-plugin? It shouldn't be hard to change that part of the code. (As Stefan mentioned: please note that only the coverage plugin is supported anymore).

Will try that. Question - What's the importance of this "zipping" step? Is it being used? Does deleting it will cause some issue?

uhafner commented 4 days ago

Hi @prsice, We suffer from the same issue. Did you able to solve this issue without .gitignore the zip file? @uhafner As a suggestion, is it possible to delete the zip file once the plugin finished running?

Both options are possible, yes. Interested in providing a PR for the coverage-plugin? It shouldn't be hard to change that part of the code. (As Stefan mentioned: please note that only the coverage plugin is supported anymore).

Will try that. Question - What's the importance of this "zipping" step? Is it being used? Does deleting it will cause some issue?

The plugin creates an HTML file for each source code file (with the covered lines highlighted). Then these files are zipped so that the there is only one communication attempt between the controller and agent. For each communication a little overhead is required so I tried to minimize this overhead.