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

五迷三道 提交于 2020-06-09 16:43:28

问题


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?


回答1:


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'



来源:https://stackoverflow.com/questions/45998130/jenkins-pipeline-docker-build-gives-error-docker-build-requires-exactly-1-a

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!