gpt4 book ai didi

docker - Jenkinsfile 与特定文件夹中的 Dockerfile

转载 作者:行者123 更新时间:2023-12-02 18:53:34 24 4
gpt4 key购买 nike

这让我抓狂:我正在尝试使用脚本化的 Jenkins 管道从存储库的特定文件夹中的 Dockerfile 构建 Docker 镜像,但它没有获得正确的路径。

这是 Jenkinsfile 中的行:

def customImage = docker.build("km3pipe:${env.BUILD_ID}",
"-f ${dockerfile} ${DOCKER_FILES_DIR}")

正如您在下面的 Jenkinslog 中所见,变量已正确解析(我还仔细检查了工作区,一切正常),但它似乎忽略了第二个参数 .dockerfiles:

[py365] + docker build -t km3pipe:13 -f py365 ./dockerfiles
[py365] unable to prepare context: unable to evaluate symlinks in Dockerfile path:
lstat /var/lib/jenkins/workspace/f-docker-image-names-for-ci-2DCL5RJ7AMH7K
IB6OCBTD57EC5DUGYZTQE5EQ6KGOSPXMUOVJP6Q/py365: no such file or directory

根据文档(https://jenkins.io/doc/book/pipeline/docker/),这应该有效:

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.

This example overrides the default Dockerfile by passing the -f flag:

node {
checkout scm
def dockerfile = 'Dockerfile.test'
def customImage = docker.build("my-image:${env.BUILD_ID}", "-f ${dockerfile} ./dockerfiles")
}

Builds my-image:${env.BUILD_ID} from the Dockerfile found at ./dockerfiles/Dockerfile.test.

最佳答案

表示此文件夹中没有名为py365的文件。您是对的,docker.build 步骤没有使用运行构建的路径。

文档遗漏了您必须在 dockerfile 语句中包含该目录:

def customImage = docker.build("km3pipe:${env.BUILD_ID}",
"-f ${DOCKER_FILES_DIR}/${dockerfile} ${DOCKER_FILES_DIR}")

关于docker - Jenkinsfile 与特定文件夹中的 Dockerfile,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50578578/

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