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
This commit is contained in:
Benjamin Stein 2017-08-29 13:39:01 -07:00 committed by GitHub
parent 6eabad7c63
commit 0ea1b5309a
2 changed files with 39 additions and 1 deletions

View file

@ -1,3 +1,3 @@
FROM tomcat:9.0-alpine
LABEL version = "1.1.2"
COPY target/petclinic.war /usr/local/tomcat/webapps/petclinic.war

View file

@ -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}"
}
}
}
}
}