Jenkins:当在Docker容器中进行Maven构建时,如何使用JUnit插件

编程入门 行业动态 更新时间:2024-10-24 10:14:29
本文介绍了Jenkins:当在Docker容器中进行Maven构建时,如何使用JUnit插件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试创建一个管道,Jenkins将在该管道上构建我的Docker映像,运行测试,然后在测试通过的情况下部署容器.问题是我在docker容器中运行了maven,并且在运行该容器之前,我实际上无法访问已发布的测试.我希望在测试通过后运行并部署Docker容器.这似乎很简单,但是我想不出一个好方法.我误会了吗?谢谢.

I am trying to create a Pipeline where Jenkins builds my Docker image, runs tests, and then deploys the container if the tests pass. The problem is that I have maven running inside the docker container, and I can't actually access the published tests until I run the container. I want the Docker container to be ran and deployed after the tests pass. This seems like a simple thing to do, but I can't think of a good way to do it. Am I misunderstanding something? Thanks.

Dockerfile:

Dockerfile:

FROM openjdk:10 as step-one COPY ./ /var/www/java/ WORKDIR /var/www/java RUN apt-get update -y && apt-get install -y maven RUN mvn clean package -X ENTRYPOINT ["java"] CMD ["-jar", "target/gs-serving-web-content-0.1.0.jar"] EXPOSE 8080

Jenkinsfile:

Jenkinsfile:

pipeline { agent any stages { stage('Build') { steps { echo 'Building..' sh 'docker build -t spring-image .' } } stage('Test') { steps { echo 'Testing..' junit '/var/www/java/target/surefire-reports/TEST-ma.SpringTest.xml' } } stage('Deploy') { steps { echo 'Deploying....' sh 'docker run -i -d --name spring-container spring-image' } } } }

推荐答案

您可以在junit之前创建一个临时容器,以提取测试结果文件以将测试结果复制到您的工厂.最后将其删除

You could create an temporary container just before junit to extract test results files to copy test result to your workspsace. And finally remove it

sh 'docker create --name temporary-container spring-image' sh 'docker cp temporary-container:/var/www/java/target/surefire-reports .' sh 'docker rm temporary-container' junit 'surefire-reports'

您还可以查看 docker-pipeline 文档,该文档为您提供一些抽象来构建docker镜像

You could also take a look do docker-pipeline documentations which provides you some abstraction to build docker images

更多推荐

Jenkins:当在Docker容器中进行Maven构建时,如何使用JUnit插件

本文发布于:2023-10-07 12:56:58,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1469449.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何使用   容器   插件   Docker   Jenkins

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!