From 0ea1b5309a788bb8527a1e6f0f743839820083fc Mon Sep 17 00:00:00 2001 From: Benjamin Stein Date: Tue, 29 Aug 2017 13:39:01 -0700 Subject: [PATCH] add dockerhub-demo jenkinsfile and add version to dockerfile (#17) * add dockerhub-demo jenkinsfile and add version to dockerfile * library is loaded in implicitly * needed to use double quotes on push * commenting out push for now * commenting out push for now * added repo to hub * separate build and push stages * formatting --- Dockerfile | 2 +- jenkinsfiles/dockerhub-demo | 38 +++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 jenkinsfiles/dockerhub-demo 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}" + } + } + } + } +}