简体   繁体   中英

Jenkins Pipeline docker.build() gives error '“docker build” requires exactly 1 argument(s)'

With this minimal Jenkins Pipeline script

node {
  docker.build("foo", "--build-arg x=y")
}

I'm getting a confusing error

"docker build" requires exactly 1 argument(s).

But as per the documentation, the signature of docker.build() is build(image[, args]) (from Jenkins /job/dockerbug/pipeline-syntax/globals#docker )

build(image[, args])

Runs docker build to create and tag the specified image from a Dockerfile in the current directory. Additional args may be added, such as '-f Dockerfile.other --pull --build-arg http_proxy=http://192.168.1.1:3128 .' . Like docker build, args must end with the build context. Returns the resulting Image object. Records a FROM fingerprint in the build.

What's going on?

My confusion was because the error message is actually coming from Docker, not Jenkins.

Docker gives this error if you don't specify a build context (as noted in the docs above).

The fix is just to add . to the end of the args parameter as per the example, eg:

node {
  docker.build("foo", "--build-arg x=y .")
}

See docker: "build" requires 1 argument. See 'docker build --help'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM