docker-maven-plugin icon indicating copy to clipboard operation
docker-maven-plugin copied to clipboard

empty build args causes builds to fail

Open JTBrinkmann opened this issue 7 months ago • 0 comments

This ticket is a continuation of #1528, which I cannot confirm to be fixed.

When a build arg in the pom.xml is set to an empty string, docker-maven-plugin throws an error:

[ERROR] Failed to execute goal io.fabric8:docker-maven-plugin:0.45.1:build (default-cli) on project test: Execution default-cli of goal io.fabric8:docker-maven-plugin:0.45.1:build failed: null value in entry: TESTARG=null -> [Help 1]

I do not see a way to legitimately set an arg to an empty string.

Reproduction pom.xml:

<project>
  <modelVersion>4.0.0</modelVersion>
  <groupId>testgroup</groupId>
  <artifactId>test</artifactId>
  <name>Test</name>
  <version>1.0.0-SNAPSHOT</version>
  <properties>
    <testproperty />
  </properties>
  <build>
    <plugins>
      <plugin>
        <groupId>io.fabric8</groupId>
        <artifactId>docker-maven-plugin</artifactId>
        <version>0.45.1</version>
        <configuration>
          <images>
            <image>
              <name>example-image</name>
              <build>
                <contextDir>${project.basedir}</contextDir>
                <args>
                  <TESTARG>${testproperty}</TESTARG>
                </args>
              </build>
            </image>
          </images>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>

Dockerfile:

FROM hello-world

(note: the <contextDir> and Dockerfile are completely irrelevant to the bug, it occurs no matter the content, even if <contextDir> is completely left out, or if the Dockerfile uses the ARG in any way or sets any default value)

failing Command (you might need to scroll right):

$ mvn docker:build
[INFO] Scanning for projects...
[INFO] 
[INFO] ---------------------------< testgroup:test >---------------------------
[INFO] Building Test 1.0.0-SNAPSHOT
[INFO]   from pom.xml
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- docker:0.45.1:build (default-cli) @ test ---
[INFO] Building tar: C:\Users\jbrinkmann\work\Hilfsmittel\tmp-mvn-docker-bug\target\docker\example-image\tmp\docker-build.tar
[INFO] DOCKER> [example-image:latest]: Created docker-build.tar in 124 milliseconds
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  3.282 s
[INFO] Finished at: 2025-03-12T17:05:41+01:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal io.fabric8:docker-maven-plugin:0.45.1:build (default-cli) on project test: Execution default-cli of goal io.fabric8:docker-maven-plugin:0.45.1:build failed: null value in entry: TESTARG=null -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:       
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginExecutionException

It does work if the build arg is a non-empty string, e.g.:

$ mvn docker:build -Dtestproperty=1                                       
[INFO] Scanning for projects...
[INFO] 
[INFO] ---------------------------< testgroup:test >---------------------------
[INFO] Building Test 1.0.0-SNAPSHOT
[INFO]   from pom.xml
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- docker:0.45.1:build (default-cli) @ test ---
[INFO] Building tar: C:\Users\jbrinkmann\work\Hilfsmittel\tmp-mvn-docker-bug\target\docker\example-image\tmp\docker-build.tar
[INFO] DOCKER> [example-image:latest]: Created docker-build.tar in 121 milliseconds
[INFO] DOCKER> [example-image:latest]: Built image sha256:bfbb0cc14f13f9ed1ae86abc2b9f11181dc50d779807ed3a3c5e55a6936dbdd5
[INFO] DOCKER> example-image: Removed dangling image sha256:498a000f370d8c37927118ed80afe8adc38d1edcbfc071627d17b25c88efcab0
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  3.827 s
[INFO] Finished at: 2025-03-12T17:07:28+01:00
[INFO] ------------------------------------------------------------------------

I was able to reproduce this issue with several versions, such as 0.30.0, 0.39.0, 0.42.0, 0.43.3, 0.44.0, 0.45.1

[ERROR] Failed to execute goal io.fabric8:docker-maven-plugin:0.39.0:build (default-cli) on project test: Execution default-cli of goal io.fabric8:docker-maven-plugin:0.39.0:build failed: null value in entry: TESTARG=null ->

JTBrinkmann avatar Mar 12 '25 16:03 JTBrinkmann