Jenkins Pipeline docker.build()给出错误’“docker build”只需要1个参数’

前端之家收集整理的这篇文章主要介绍了Jenkins Pipeline docker.build()给出错误’“docker build”只需要1个参数’前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

使用这个最小的Jenkins管道脚本

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

我遇到了一个令人困惑的错误

“docker build” requires exactly 1 argument(s).

但根据文档,docker.build()的签名是build(image [,args])(来自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.

这是怎么回事?

最佳答案
我的困惑是因为错误信息实际上来自Docker,而不是Jenkins.

如果您未指定构建上下文,则Docker会出现此错误(如上文中所述).

修复只是添加.根据示例到args参数的末尾,例如:

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

docker: “build” requires 1 argument. See ‘docker build –help’

猜你在找的Docker相关文章