Jenkinsfile 自定义 docker 容器 "could not find FROM instruction"

Jenkinsfile custom docker container "could not find FROM instruction"

我刚刚开始使用 Jenkinsfiles 和 Docker 如果这很明显,我们深表歉意。

我有一个包含 Docker 文件和 Jenkins 文件的存储库。

Docker文件只是通过添加几个依赖项和构建工具来扩展基础 Ubuntu 映像(ubuntu:trusty)。

Jenkinsfile 目前只为我构建 Docker 容器:

node('docker') {
stage "Prepare environment"
    checkout scm
    docker.build('build-image')
}

当我 运行 构建 Jenkins 时,输出日志显示 Docker 容器已成功创建,但就在它应该成功完成之前,我得到:

Successfully built 04ba77c72c74
[Pipeline] dockerFingerprintFrom
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
[Bitbucket] Notifying commit build result
[Bitbucket] Build result notified
ERROR: could not find FROM instruction in /home/emackenzie/jenkins/workspace/001_test-project_PR-1-ROWUV6YLERZKDQWCAGJK5MQHNKY7RJRHC2TH4DNOZSEKE6PZB74A/Dockerfile
Finished: FAILURE

我无法从互联网上找到任何关于为什么我会收到此错误的指导,因此非常感谢任何帮助


Docker文件:

FROM    ubuntu:trusty
MAINTAINER Ed Mackenzie

# setup apt repos
RUN echo "deb http://archive.ubuntu.com/ubuntu/ trusty multiverse" >> /etc/apt/sources.list \
&& echo "deb-src http://archive.ubuntu.com/ubuntu/ trusty multiverse" >> /etc/apt/sources.list \
&& apt-get update

# python
RUN apt-get install -y python python-dev python-openssl

这是因为您的 FROM 行使用白色制表符 space,而不是 space(s)。这是 Jenkins CI Docker 工作流插件中的一个错误,它期望该行以 FROM 开头,后跟 space.

来自 Github 上的 jenkinsci/docker-workflow-plugin 来源:

String fromImage = null;

// ... other stuff

if (line.startsWith("FROM ")) {
    fromImage = line.substring(5);
    break;
}

// ... other stuff ...

if (fromImage == null) {
    throw new AbortException("could not find FROM instruction in " + dockerfile);
}

如果您使用 spaces 而不是制表符,它应该可以正常工作。

我只是 运行 遇到了同样的问题,这是一个类似的解决方案。检查文件的开头是否用 BOM 编码(这可以用 Notepad++ 之类的东西来完成)。如果是这样,请在没有标记的情况下保存它,插件将停止抱怨。

错误可以通过将"from"语句更改为"FROM"

来解决