I'm trying to build a CI/CD pipeline using Jenkins. I am using a maven project. I would like to use the .jar file produced by mvn package in another pipeline stage. is that possible?
pipeline {
agent none
stages{
stage('Build Jar'){
agent {
docker {
image 'maven:3-alpine'
args '-v /root/.m2:/root/.m2'
}
}
steps {
sh 'mvn package'
stash includes: 'target/*.jar', name: 'targetfiles'
}
}
stage('Deploy') {
agent {
node {
label 'DockerDefault'
}
}
steps {
script{
def image = docker.build("image-name:test", ' .')
}
}
}
}
}
This is the Dockerfile:
#install OS
FROM centos
#install java
RUN yum install -y java
#make directory structure to store temporary files
RUN mkdir -p /store
#put jar into container
ADD target/AdWordsProducer-1.0-SNAPSHOT-shaded.jar adwordsproducer.jar
#run jar
ENTRYPOINT ["java", "-jar", "/adwordsproducer.jar"]