diff --git a/Dockerfile b/Dockerfile index 1624cb6ef..ba768d1fa 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,3 +1,3 @@ FROM tomcat:9.0-alpine - +LABEL version = "1.1.2" COPY target/petclinic.war /usr/local/tomcat/webapps/petclinic.war diff --git a/jenkinsfiles/dockerhub-demo b/jenkinsfiles/dockerhub-demo new file mode 100644 index 000000000..b3faa52ab --- /dev/null +++ b/jenkinsfiles/dockerhub-demo @@ -0,0 +1,38 @@ +pipeline { + agent none + stages { + stage('Build') { + agent { + docker { + image 'maven:3.5.0' + } + } + steps { + sh 'mvn clean install -DskipTests=true -B' + } + } + stage('Build container') { + agent any + steps { + script { + sh "docker build -t liatrio/petclinic-tomcat:${env.BRANCH_NAME} ." + if ( ${env.BRANCH_NAME} == 'master' ) { + def containerVersion = getVersionFromContainer("liatrio/petclinic-tomcat:${env.BRANCH_NAME}") + failIfVersionExists("liatrio","petclinic-tomcat",containerVersion) + sh "docker build -t liatrio/petclinic-tomcat:${containerVersion} ." + } + } + } + } + stage('Push to dockerhub') { + agent any + steps { + script { + if ( ${env.BRANCH_NAME} == 'master' ) + sh "docker push liatrio/petclinic-tomcat:${containerVersion}" + else sh "docker push liatrio/petclinic-tomcat:${env.BRANCH_NAME}" + } + } + } + } +}