diff --git a/Jenkinsfile b/Jenkinsfile index 0423fbf13..13617b3b9 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -12,7 +12,7 @@ pipeline { configFileProvider( [configFile(fileId: 'nexus', variable: 'MAVEN_SETTINGS')]) { sh 'mvn -s $MAVEN_SETTINGS clean deploy -DskipTests=true -B' - } + } } } } diff --git a/jenkinsfiles/full-demo b/jenkinsfiles/full-demo index 3b366d9aa..98f349beb 100644 --- a/jenkinsfiles/full-demo +++ b/jenkinsfiles/full-demo @@ -29,14 +29,23 @@ pipeline { stage('Build container') { agent any steps { - sh 'docker build -t petclinic-tomcat .' + script { + sh "docker build -t liatrio/petclinic-tomcat:${env.BRANCH_NAME} ." + if ( env.BRANCH_NAME == 'master' ) { + pom = readMavenPom file: 'pom.xml' + containerVersion = pom.version + /*Need to check if version exists in the future*/ + /*failIfVersionExists("liatrio","petclinic-tomcat",containerVersion)*/ + sh "docker build -t liatrio/petclinic-tomcat:${containerVersion} ." + } + } } } stage('Run local container') { agent any steps { sh 'docker rm -f petclinic-tomcat-temp || true' - sh 'docker run -d --network=${LDOP_NETWORK_NAME} --name petclinic-tomcat-temp petclinic-tomcat' + sh "docker run -d --network=${LDOP_NETWORK_NAME} --name petclinic-tomcat-temp liatrio/petclinic-tomcat:${env.BRANCH_NAME}" } } stage('Smoke-Test & OWASP Security Scan') { @@ -57,6 +66,22 @@ pipeline { sh 'docker rm -f petclinic-tomcat-temp || true' } } + stage('Push to dockerhub') { + agent any + steps { + withCredentials([usernamePassword(credentialsId: 'dockerhub', passwordVariable: 'dockerPassword', usernameVariable: 'dockerUsername')]){ + script { + sh "docker login -u ${env.dockerUsername} -p ${env.dockerPassword}" + if ( env.BRANCH_NAME == 'master' ) { + sh "docker push liatrio/petclinic-tomcat:${containerVersion}" + } + else { + sh "docker push liatrio/petclinic-tomcat:${env.BRANCH_NAME}" + } + } + } + } + } stage('Deploy to dev') { agent any steps {