我正在构建FreePascal Web应用程序,并且正在使用CI / CD的Jenkins管道。
我有以下Dockerfile(不是世界上最高效的文件,但现在还可以):
FROM ubuntu as builder
RUN apt-get update -y
RUN apt-get install -y libcurl4-openssl-dev
RUN apt-get install -y fpc
ARG BUILD_TYPE=prod
ENV BUILD_TYPE=${BUILD_TYPE}
COPY . /var/www/app
WORKDIR /var/www/app
RUN make build
RUN make build-tests
FROM actilis/httpd-cgi
RUN yum -y install postgresql
ENV HTTPD_ENABLE_CGI=true
COPY ./httpd.conf /etc/httpd/conf.d/000-default.conf
COPY --from=builder /var/www/app/public/app.cgi /var/www/app/
COPY --from=builder /var/www/app/bin/unit/TestRunner /var/www/app/
当我sh
进入这个容器并且cd
进入/var/www/app
时,我看到./TestRunner
和app.cgi
;这分别是我的单元测试和cgi应用程序可执行文件。我可以跑步:
./TestRunner --format=xml --all
,所有测试将运行。到目前为止一切顺利。
问题是当我尝试在Jenkins上重新创建相同的设置时。 我正在使用以下Jenkinsfile:
pipeline {
agent none
stages {
stage('Back-end') {
agent {
dockerfile {
filename 'Dockerfile'
dir 'backend'
}
}
steps {
sh './TestRunner --format=xml --all'
}
}
stage('Front-end') {
agent {
docker { image 'node:7-alpine' }
}
steps {
sh 'node --version'
}
}
}
}
在Jenkins上,找不到./TestRunner
文件。输出为:
+ docker build -t 181ef0bcb3bf204f1879365a51eb4f056599fcbc -f backend/Dockerfile backend
Sending build context to Docker daemon 1.405MB
Step 1/16 : FROM ubuntu as builder
---> 4c108a37151f
Step 2/16 : RUN apt-get update -y
---> Using cache
---> 23006844dbe3
Step 3/16 : RUN apt-get install -y libcurl4-openssl-dev
---> Using cache
---> 85f33caeb6fa
Step 4/16 : RUN apt-get install -y fpc
---> Using cache
---> 4179833a6dc6
Step 5/16 : ARG BUILD_TYPE=prod
---> Using cache
---> 175016eb89cd
Step 6/16 : ENV BUILD_TYPE=${BUILD_TYPE}
---> Using cache
---> 93f40d4821b4
Step 7/16 : COPY . /var/www/app
---> Using cache
---> ba927c86c8f0
Step 8/16 : WORKDIR /var/www/app
---> Using cache
---> ad053831767b
Step 9/16 : RUN make build
---> Using cache
---> 7cee4fa21f10
Step 10/16 : RUN make build-tests
---> Using cache
---> 1d7db41bc613
Step 11/16 : FROM actilis/httpd-cgi
---> 98b08d011dc9
Step 12/16 : RUN yum -y install postgresql
---> Using cache
---> 2dd8ccfec261
Step 13/16 : ENV HTTPD_ENABLE_CGI=true
---> Using cache
---> 1a78db6d4788
Step 14/16 : COPY ./httpd.conf /etc/httpd/conf.d/000-default.conf
---> Using cache
---> 4147b79edb69
Step 15/16 : COPY --from=builder /var/www/app/public/app.cgi /var/www/app/
---> Using cache
---> 41f28ebd3602
Step 16/16 : COPY --from=builder /var/www/app/bin/unit/TestRunner /var/www/app/
---> Using cache
---> f897e3055e8b
Successfully built f897e3055e8b
Successfully tagged 181ef0bcb3bf204f1879365a51eb4f056599fcbc:latest
[Pipeline] dockerFingerprintFrom
[Pipeline] sh
+ docker inspect -f . 181ef0bcb3bf204f1879365a51eb4f056599fcbc
.
[Pipeline] withDockerContainer
Jenkins does not seem to be running inside a container
$ docker run -t -d -u 111:115 -w /home/jenkins/workspace/ipeline-2_chore_jenkins-pipeline -v /home/jenkins/workspace/ipeline-2_chore_jenkins-pipeline:/home/jenkins/workspace/ipeline-2_chore_jenkins-pipeline:rw,z -v /home/jenkins/workspace/ipeline-2_chore_jenkins-pipeline@tmp:/home/jenkins/workspace/ipeline-2_chore_jenkins-pipeline@tmp:rw,z -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** 181ef0bcb3bf204f1879365a51eb4f056599fcbc cat
$ docker top c669acb2b4a88c4ea0cfc1f5682f2cfd2a41052235767ac330800f7bcd6b35b4 -eo pid,comm
[Pipeline] {
[Pipeline] sh
+ find . -name '*TestRunner*'
./backend/tests/TestRunner.pas
[Pipeline] sh
+ ./TestRunner --format=xml --all
/home/jenkins/workspace/ipeline-2_chore_jenkins-pipeline@tmp/durable-43156271/script.sh: line 1: ./TestRunner: No such file or directory
[Pipeline] }
$ docker stop --time=1 c669acb2b4a88c4ea0cfc1f5682f2cfd2a41052235767ac330800f7bcd6b35b4
$ docker rm -f c669acb2b4a88c4ea0cfc1f5682f2cfd2a41052235767ac330800f7bcd6b35b4
[Pipeline] // withDockerContainer
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // node
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Front-end)
Stage "Front-end" skipped due to earlier failure(s)
[Pipeline] }
[Pipeline] // stage
[Pipeline] End of Pipeline
我调查了容器中的内容,发现的都是Github的原始源文件。即使日志输出显示Docker成功运行,但可执行文件也不存在。
有人可以解释发生了什么以及如何解决此问题吗? 我是Jenkins的新手,所以我可能会犯一个基本的错误。