docker-plugin
docker-plugin copied to clipboard
Passing job parameters into Docker build arguments does not work
Jenkins and plugins versions report
Environment
Paste the output here
What Operating System are you using (both controller, and any agents involved in the problem)?
Debian 11, jenkins run in official docker image jenkins/jenkins
.
Reproduction steps
- Create parametrized job and set up some parameter, NAME=VALUE for example.
- Configure Docker build/publish stage in build with build args with content: `--build-arg NAME=${NAME}
- Run job
Expected Results
Build args passed to docker build command in form --build-arg NAME=VALUE
Actual Results
Build args passed to docker build command in form --build-arg NAME=${NAME}
, which no sense.
Anything else?
With this bug, the Docker plugin is almost useless for building images parameterized with job arguments.
While I can understand that this code doesn't work the way you expect, that's because it was never designed/intended to do that - it was never intended to be useful for your scenario.
FYI the docker-build functionality is very basic and a bit gnarly; you're probably better off using something else as that's really not "core functionality" (and there's deficiencies in the docker API that means it can struggle to work at all e.g. with a traditional swarm). I'd suggest that, if you use it at all, you use it to build yourself a single docker image that you then use as a Jenkins agent to build everything else. i.e. use it purely to "bootstrap" your build environment.
A PR enhancing the code so that variable expansion happens would be welcomed though so, if you're keen on getting that functionality added, please do so.
"--build-arg" passed through agent from credentials does not seem to be working either, so what is solution with build arguments to pass credentials?
TL;DR: "not this"
You could use this plugin to spin up a container from which you can run docker build
commands from a simple shell step.
i.e. use this plugin purely as a means of providing Jenkins agent executors; that's what it's designed to do.
FYI the "build step" functionality this plugin contains is not really "core functionality" to this plugin and maintaining/enhancing these various build steps has never been a priority; there's a strong argument that these build steps should be split out into a separate plugin ... but nobody's volunteered to do that work either.