传递给 docker.build 几个 --build-arg 参数
Pass to docker.build several --build-arg arguments
正在尝试在 Jenkinsfile 中传递两个构建参数。
适用于单个 --build-arg:
app = docker.build("myimg:${Version}", "--build-arg VERSION=${Version} --no-cache ."
但不适用于几个:
app = docker.build("myimg:${Version}", "--build-arg VERSION=${Version} --build-arg CODEARTIFACT_TOKEN=${CODEARTIFACT_TOKEN} --no-cache ."
输出错误:"docker build" requires exactly 1 argument.
如何传递两个或更多构建参数?
感觉这是 Jenkins 对你的期望。
Jenkins 文档说
It is possible to pass other arguments to docker build by adding them to the second argument of the build() method. When passing arguments this way, the last value in the that string must be the path to the docker file and should end with the folder to use as the build context)
您应该尝试在上下文 .
之前添加 -f ${dockerfile}
所以看起来像这样
app = docker.build("myimg:${Version}", "--build-arg VERSION=${Version} --build-arg CODEARTIFACT_TOKEN=${CODEARTIFACT_TOKEN} --no-cache -f Dockerfile ."
假设您的 Dockerfile 在当前文件夹中。
这是文档:
- 列表项
问题不在于构建参数的数量,而在于 CODEARTIFACT_TOKEN 变量。
CODEARTIFACT_TOKEN 变量可能包含新行。
因此这一行解决了问题:
CODEARTIFACT_TOKEN = CODEARTIFACT_TOKEN.trim()
正在尝试在 Jenkinsfile 中传递两个构建参数。
适用于单个 --build-arg:
app = docker.build("myimg:${Version}", "--build-arg VERSION=${Version} --no-cache ."
但不适用于几个:
app = docker.build("myimg:${Version}", "--build-arg VERSION=${Version} --build-arg CODEARTIFACT_TOKEN=${CODEARTIFACT_TOKEN} --no-cache ."
输出错误:"docker build" requires exactly 1 argument.
如何传递两个或更多构建参数?
感觉这是 Jenkins 对你的期望。
Jenkins 文档说
It is possible to pass other arguments to docker build by adding them to the second argument of the build() method. When passing arguments this way, the last value in the that string must be the path to the docker file and should end with the folder to use as the build context)
您应该尝试在上下文 .
之前添加 -f ${dockerfile}
所以看起来像这样
app = docker.build("myimg:${Version}", "--build-arg VERSION=${Version} --build-arg CODEARTIFACT_TOKEN=${CODEARTIFACT_TOKEN} --no-cache -f Dockerfile ."
假设您的 Dockerfile 在当前文件夹中。
这是文档:
- 列表项
问题不在于构建参数的数量,而在于 CODEARTIFACT_TOKEN 变量。
CODEARTIFACT_TOKEN 变量可能包含新行。
因此这一行解决了问题:
CODEARTIFACT_TOKEN = CODEARTIFACT_TOKEN.trim()