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

Passing job parameters into Docker build arguments does not work

Open Aleksei-Badyaev opened this issue 2 years ago • 3 comments

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

  1. Create parametrized job and set up some parameter, NAME=VALUE for example.
  2. Configure Docker build/publish stage in build with build args with content: `--build-arg NAME=${NAME}
  3. 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.

Aleksei-Badyaev avatar Jun 29 '22 17:06 Aleksei-Badyaev

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.

pjdarton avatar Jul 14 '22 17:07 pjdarton

"--build-arg" passed through agent from credentials does not seem to be working either, so what is solution with build arguments to pass credentials?

rimvislt avatar Nov 12 '22 23:11 rimvislt

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.

Peter-Darton-i2 avatar Nov 15 '22 13:11 Peter-Darton-i2