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

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

问题描述

有了这个最小的Jenkins Pipeline脚本

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])(来自詹金斯/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-arg http_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:"build"需要1个参数.参见'docker build --help'

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

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