According to Docker's docs, running docker build --build-arg VARIABLE should be equivalent to docker build --build-arg VARIABLE=${VARIABLE}. However, the Docker Pipeline plugin throws an exception if this usage is passed to docker.build in a pipeline. (See attached Jenkinsfile and log).
As shown in the log, these arguments are passed to the Docker client and the image builds fine. Only after this has happened is the exception logged and the build is marked as failed, despite the successful Docker build.
A workaround would be to just use --build-arg SSH_KEY="${env.SSH_KEY}", but as this would result in the private key being printed to the build logs I'm not really happy with that approach.
I'm going to +1 this issue as a totally annoying problem here as I'm working on using Jenkins Dockerfiles that depend on an upstream private image as well as a private-key needing to be passed in in order to perform git clones of private repositories as part of a dependency management step in the primary Dockerfile. I too don't like how the credentials get displayed willy-nilly as soon as they become multiline parameters.
Thx for your feedback Eli Treuherz I tried to reply yor comments in code. It seems IsMapWithSize is not available without further work (hamcrest 1.3 limit?). I'd suggest to keep changes on the tests in line with all tests in the class.
A fix for this issue was just released in Docker Pipeline plugin version 1.19. From the release notes:
Deprecate the dockerFingerprintFrom and dockerFingerprintRun steps and stop calling them during docker.build and image.run. Fixes various issues with Dockerfile parsing and parsing arguments to docker build.