[英]Docker Multi Stage Build access Test Reports in Jenkins when Tests Fail
I am doing a multi stage build in docker to separate the app from testing.我正在 docker 中进行多阶段构建,以将应用程序与测试分开。 Now at some point in my Dockerfile I run:
现在在我的 Dockerfile 中的某个时刻我运行:
RUN pytest --junit=test-reports/junit.xml
In my Jenkinsfile respectivly I do:在我的 Jenkinsfile 中,我分别做:
def app = docker.build("app:${BUILD_NUMBER}", "--target test .")
app.inside {
sh "cp -r /app/test-reports test-reports"
}
junit 'test-reports/junit.xml'
Now if my test fail, the build fails which is good.现在,如果我的测试失败,则构建失败,这很好。 But the rest of the stage is not executed, ie I dont have access to the test-reports folder.
但是stage的rest没有被执行,即我无权访问test-reports文件夹。 How can I manage that?
我该如何管理?
I resolved similar task by using always block after build stage.我通过在构建阶段后使用 always 块解决了类似的任务。 Please check if below code can help.
请检查以下代码是否有帮助。
always{
script{
sh '''#!/bin/bash
docker create -it --name test_report app:${BUILD_NUMBER} /bin/bash
docker cp test_report:/app/test-reports ./test-reports
docker rm -f test_report
'''
}
junit 'test-reports/junit.xml'
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.