Jenkins Pipeline docker.build() 给出错误“docker build"恰好需要 1 个参数' [英] Jenkins Pipeline docker.build() gives error '"docker build" requires exactly 1 argument(s)'

查看:33
本文介绍了Jenkins Pipeline docker.build() 给出错误“docker build"恰好需要 1 个参数'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用这个最小的 Jenkins 流水线脚本

With this minimal Jenkins Pipeline script

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

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

I'm getting a confusing error

docker build"只需要 1 个参数.

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

但根据文档, docker.build() 的签名是 build(image[, args]) (来自 Jenkins /job/dockerbug/pipeline-syntax/globals#docker)

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])

运行 docker build 来创建和标记指定的来自当前目录中的 Dockerfile 的图像.额外的参数可能被添加,如 '-f Dockerfile.other --pull --build-arghttp_proxy=http://192.168.1.1:3128 .'.像 docker build 一样,args 必须以构建上下文结束.返回生成的 Image 对象.在构建中记录 FROM 指纹.

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.

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

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

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

解决方法只是按照示例将 . 添加到 args 参数的末尾,例如:

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 .")
}

请参阅 docker:构建"需要 1 个参数.请参阅docker build --help"

这篇关于Jenkins Pipeline docker.build() 给出错误“docker build"恰好需要 1 个参数'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆