Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-73505

Source directories set through glob syntax are ignored

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Minor Minor
    • prism-api-plugin
    • None
    • jenkins 2.452.3; coverage-plugin 1.16.1

      I have a project with multiple (ie, ~100) modules. From the project directory, code is in

      foo/src
      bar/src
      baz/src
      (etc)

      and coverage reports are in

      foo/generated/reports/jacoco/test/jacocoTestReport.xml
      bar/generated/reports/jacoco/test/jacocoTestReport.xml
      baz/generated/reports/jacoco/test/jacocoTestReport.xml
      (etc)

      My coverage DSL block is

      recordCoverage(
          sourceDirectories: [[path: 'glob:*/src']],
          tools: [[pattern: '*/generated/reports/jacoco/test/jacocoTestReport.xml']]
      )
      

      The plugin is able to find coverage reports in the expected directories:

      [Coverage] Successfully parsed file '/var/lib/jenkins/workspace/main/foo/generated/reports/jacoco/test/jacocoTestReport.xml'
      [Coverage] MODULE: 100.00% (1/1)
      [Coverage] PACKAGE: 25.00% (1/4)
      [Coverage] FILE: 11.11% (1/9)
      [Coverage] CLASS: 18.18% (2/11)
      [Coverage] METHOD: 4.26% (4/94)
      [Coverage] LINE: 1.48% (6/405)
      [Coverage] BRANCH: 1.59% (1/63)
      [Coverage] INSTRUCTION: 2.20% (40/1815)
      [Coverage] COMPLEXITY: 127
      [Coverage] COMPLEXITY_MAXIMUM: 6
      [Coverage] COMPLEXITY_DENSITY: 127/405
      [Coverage] LOC: 405
      [Coverage] Successfully processed file 'foo/generated/reports/jacoco/test/jacocoTestReport.xml'
      

      but is unable to resolve any source code, and doesn't search the path I set:

      [Coverage] [-ERROR-] Errors while resolving source files on agent:
      [Coverage] [-ERROR-] - Source file 'ca/uvic/dmas/core/system/ui/services/LayoutAccount.java' not found
      [Coverage] [-ERROR-]   ... skipped logging of 5588 additional errors ...
      [Coverage] Resolving source code files...
      [Coverage] Searching for source code files in '/var/lib/jenkins/workspace/main/src/main/java'
      [Coverage] -> finished resolving of absolute paths (found: 0, not found: 5589)
      

      In addition, the Snippet Generator reports an error when I set the source path to "glob:*/src":

          [JENKINS-73505] Source directories set through glob syntax are ignored

          Patrick Conley added a comment - - edited

          I tried with several alternate paths as well. Assuming it's a glob with

          recordCoverage(
              sourceDirectories: [[path: '*/src']],
              tools: [[pattern: '*/generated/reports/jacoco/test/jacocoTestReport.xml']]
          )
          

          also fails, but does claim to search my path (my speculation is that it's treating "*" as a regular string)

          [Coverage] [-ERROR-] Errors while resolving source files on agent:
          [Coverage] [-ERROR-] - Source file 'ca/uvic/dmas/core/system/ui/services/LayoutAccount.java' not found
          [Coverage] [-ERROR-]   ... skipped logging of 5588 additional errors ...
          [Coverage] Resolving source code files...
          [Coverage] Searching for source code files in '/var/lib/jenkins/workspace/main/src/main/java'
          [Coverage] Searching for source code files in '/var/lib/jenkins/workspace/main/*/src'
          [Coverage] -> finished resolving of absolute paths (found: 0, not found: 5589)
          

          An explicit path

          recordCoverage(
              sourceDirectories: [[path: 'foo/src']],
              tools: [[pattern: '*/generated/reports/jacoco/test/jacocoTestReport.xml']]
          )
          

          does find source code in foo, logging

          [Coverage] Resolving source code files...
          [Coverage] Searching for source code files in:
          [Coverage] -> /var/lib/jenkins/workspace/main/src/main/java
          [Coverage] -> /var/lib/jenkins/workspace/main/foo/src
          [Coverage] -> finished resolving of absolute paths (found: 3339, not found: 2250)
          [Coverage] Making paths of 3339 source code files relative to workspace root...
          

          but this approach isn't feasible for 100+ source directories.

          Patrick Conley added a comment - - edited I tried with several alternate paths as well. Assuming it's a glob with recordCoverage( sourceDirectories: [[path: '*/src' ]], tools: [[pattern: '*/generated/reports/jacoco/test/jacocoTestReport.xml' ]] ) also fails, but does claim to search my path (my speculation is that it's treating "*" as a regular string) [Coverage] [-ERROR-] Errors while resolving source files on agent: [Coverage] [-ERROR-] - Source file 'ca/uvic/dmas/core/system/ui/services/LayoutAccount.java' not found [Coverage] [-ERROR-] ... skipped logging of 5588 additional errors ... [Coverage] Resolving source code files... [Coverage] Searching for source code files in '/ var /lib/jenkins/workspace/main/src/main/java' [Coverage] Searching for source code files in '/ var /lib/jenkins/workspace/main/*/src' [Coverage] -> finished resolving of absolute paths (found: 0, not found: 5589) An explicit path recordCoverage( sourceDirectories: [[path: 'foo/src' ]], tools: [[pattern: '*/generated/reports/jacoco/test/jacocoTestReport.xml' ]] ) does find source code in foo, logging [Coverage] Resolving source code files... [Coverage] Searching for source code files in: [Coverage] -> / var /lib/jenkins/workspace/main/src/main/java [Coverage] -> / var /lib/jenkins/workspace/main/foo/src [Coverage] -> finished resolving of absolute paths (found: 3339, not found: 2250) [Coverage] Making paths of 3339 source code files relative to workspace root... but this approach isn't feasible for 100+ source directories.

          Ulli Hafner added a comment -

          What happens when you use glob:**/src/main/java?

          Ulli Hafner added a comment - What happens when you use glob:**/src/main/java ?

          Aha, I didn't try **

          recordCoverage(
              sourceDirectories: [[path: 'glob:**/src']],
              tools: [[pattern: '*/generated/reports/jacoco/test/jacocoTestReport.xml']]
          )
          

          logs

          [Coverage] Resolving source code files...
          [Coverage] Searching for source code files in:
          [Coverage] -> /var/lib/jenkins/workspace/main/foo/src
          [Coverage] -> /var/lib/jenkins/workspace/main/bar/src
          [Coverage] -> /var/lib/jenkins/workspace/main/baz/resources/static/build/node_modules/plotty/src
          [Coverage] -> /var/lib/jenkins/workspace/main/qux/src
          [Coverage] -> resolved absolute paths for all 5589 source files
          [Coverage] Making paths of 5589 source code files relative to workspace root...
          

          It would be nice to be able to use a single * to avoid searching nested src directories, but this is fine.

          Thanks

          Patrick Conley added a comment - Aha, I didn't try ** recordCoverage( sourceDirectories: [[path: 'glob:**/src' ]], tools: [[pattern: '*/generated/reports/jacoco/test/jacocoTestReport.xml' ]] ) logs [Coverage] Resolving source code files... [Coverage] Searching for source code files in: [Coverage] -> / var /lib/jenkins/workspace/main/foo/src [Coverage] -> / var /lib/jenkins/workspace/main/bar/src [Coverage] -> / var /lib/jenkins/workspace/main/baz/resources/ static /build/node_modules/plotty/src [Coverage] -> / var /lib/jenkins/workspace/main/qux/src [Coverage] -> resolved absolute paths for all 5589 source files [Coverage] Making paths of 5589 source code files relative to workspace root... It would be nice to be able to use a single * to avoid searching nested src directories, but this is fine. Thanks

          Ulli Hafner added a comment - - edited

          Normally the single * should work as well, maybe the problem is the "main" prefix? So main/*/src? The glob is expanded starting with the agents workspace directory.

          Ulli Hafner added a comment - - edited Normally the single * should work as well, maybe the problem is the "main" prefix? So main/*/src ? The glob is expanded starting with the agents workspace directory.

          Sorry, I wasn't clear with my obfuscated directory names: this is a multibranch pipeline whose branch name is "main". The build's workspace is /var/lib/jenkins/workspace/main.

          Patrick Conley added a comment - Sorry, I wasn't clear with my obfuscated directory names: this is a multibranch pipeline whose branch name is "main". The build's workspace is /var/lib/jenkins/workspace/main.

            drulli Ulli Hafner
            pconley Patrick Conley
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: