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:
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:
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'
}
}
}
}