From 7bb35e7d972f5881d91827687c1cbc6358b9ba51 Mon Sep 17 00:00:00 2001 From: HunterMayers Date: Mon, 11 Sep 2017 09:38:22 -0700 Subject: [PATCH] Changed main Jenkinsfile to push to dockerhub updated jenkinsfile replaced a couple instances of wrong account in jenkinsfile Added master branch logic and dockerhub cred updated docker login Changing master to this branch for testing reverting branch check, testing done. Added dockerhub push steps to full-demo Updated reference to tomcat image name fixed failing steps in jenkinsfile flatten jenkinsfile directory (#19) * flatten jenkinsfile directory * move full-demo jenkinsfile up one level revert root Jenkinsfile to be consistent with master Testing branch feature on full-demo Re-added a missing closing bracket Reverted to checking for master --- Jenkinsfile | 2 +- jenkinsfiles/{full-demo => }/full-demo | 30 ++++++++++++++++++++++++-- 2 files changed, 29 insertions(+), 3 deletions(-) rename jenkinsfiles/{full-demo => }/full-demo (79%) 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/full-demo b/jenkinsfiles/full-demo similarity index 79% rename from jenkinsfiles/full-demo/full-demo rename to jenkinsfiles/full-demo index 3b366d9aa..28f7ceffd 100644 --- a/jenkinsfiles/full-demo/full-demo +++ b/jenkinsfiles/full-demo @@ -29,14 +29,24 @@ 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 'env | grep LDOP' + 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 +67,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 {