gpt4 book ai didi

docker - Jenkins Pipeline docker.build() 给出错误 '"docker build“需要 1 个参数”

转载 作者:IT老高 更新时间:2023-10-28 12:42:56 25 4
gpt4 key购买 nike

使用这个最小的 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 - Jenkins Pipeline docker.build() 给出错误 '"docker build“需要 1 个参数”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45998130/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com