Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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?

like image 265
John Carter Avatar asked Sep 01 '17 10:09

John Carter


People also ask

How do I fix the docker build requires exactly one argument?

By default we provided dot(.) in the command which specifies the Docker daemon to use the shell's current working directory as the build context: $ docker build . In order to solve this issue, we need to provide the correct file name with -f option.

What is the dot at the end of docker build?

Dockerfile image building Note that the dot at the end tells the docker build command to look for the Dockerfile in the current directory.

What is a docker build?

Description. The docker build command builds Docker images from a Dockerfile and a “context”. A build's context is the set of files located in the specified PATH or URL . The build process can refer to any of the files in the context. For example, your build can use a COPY instruction to reference a file in the context ...


1 Answers

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'

like image 191
John Carter Avatar answered Oct 08 '22 18:10

John Carter