Search code examples
dockerjenkinsmaven-pluginfilepathpmd

Jenkins PMD details from docker: Copying the source file failed


I'm running Jenkins maven task inside docker image. My task generates pmd.xml which is then parsed by Jenkins plugin.

The problem is that path inside docker image is different that Jenkins workspace. This results in PMD view to crash when redirecting to source. pmd.xml with absolute paths looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<pmd xmlns="http://pmd.sourceforge.net/report/2.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://pmd.sourceforge.net/report/2.0.0 http://pmd.sourceforge.net/report_2_0_0.xsd"
    version="6.21.0" timestamp="2021-09-28T09:14:56.411">
<file name="/usr/src/mymaven/mymodule/src/main/java/my/org/MyFile.java">
<violation beginline="124" endline="124" begincolumn="40" endcolumn="145"> 
...
</violation>
</file>
</pmd>

Jenkins error:

Copying the source file '/usr/src/mymaven/...' from the workspace to the build folder 'xxxxx.tmp' on the Jenkins master failed.
If you are building on a slave: please check if the file is accessible under '$JENKINS_HOME/[job-name]//usr/src/mymaven/...

I want to achieve relative paths in my pmd.xml report, in this case it would be:

...
<file name="mymodule/src/main/java/my/org/MyFile.java">
...

How can I achieve relative paths using maven-pmd-plugin plugin?

                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-pmd-plugin</artifactId>
                <version>3.13.0</version>

Is there any other way to solve displaying pmd details in source code for Jenkins build inside docker?

UPDATE: Adding docker-compose.yml snippet

version: "3.7"
services:
  maven:
    image: maven:3-openjdk-11-slim
    volumes:
      - .:/usr/src/mymaven
    command:
      [ "mvn",
        "clean",
        "install",
        "pmd:pmd"
      ]
...

Solution

  • I solved the problem by changing docker volume mount point to Jenkins WORKSPACE path.

    ...
       volumes:
          - "${WORKSPACE}:${WORKSPACE}"
    ...