From cdd84ac58838c0e133b292476d005e5a3f6ed85e Mon Sep 17 00:00:00 2001 From: A-hash-bit <58227483+A-hash-bit@users.noreply.github.com> Date: Tue, 16 Aug 2022 09:32:58 +0530 Subject: [PATCH] Update Jenkinsfile --- Jenkinsfile | 71 +++++++++++++++++++++++++++++++++-------------------- 1 file changed, 44 insertions(+), 27 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 7cb81bea6..8eaaf0f26 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,30 +1,47 @@ -node { - def WORKSPACE = "/var/lib/jenkins/workspace/petclinic" - def dockerImageTag = "petclinic${env.BUILD_NUMBER}" - -try{ - stage('Clone Repo') { - // for display purposes - // Get some code from a GitHub repository - echo "========executing checkout========" - git url:"https://github.com/A-hash-bit/spring-petclinic.git", branch:"main" - echo "========checkout done========" - } - stage('Build docker') { - echo "========executing docker build========" - dockerImage = docker.build("petclinic:${env.BUILD_NUMBER}") - } - - stage('Deploy docker'){ - echo "Docker Image Tag Name: ${dockerImageTag}" - sh "docker stop petclinic || true && docker rm petclinic || true" - sh "docker run --name petclinic -d -p 8081:8081 petclinic:${env.BUILD_NUMBER}" - } -}catch(e){ - currentBuild.result = "FAILED" - throw e -}finally{ +pipeline{ + agent any - } + tools{ + maven "maven3" + } + /* + triggers{ + cron("* * * * *") + } + */ + stages{ + stage("Checkout"){ + steps{ + echo "========executing checkout========" + git url:"https://github.com/A-hash-bit/spring-petclinic.git", branch:"main" + } + + } + + stage("Build"){ + steps{ + sh "mvn clean package" + } + } + stage('Docker Build') { + agent any + steps { + echo "========executing docker build========" + sh 'docker build -t amar/petclinic:latest .' + } + } + + } + post{ + always{ + echo "========always========" + } + success{ + echo "========pipeline executed successfully ========" + } + failure{ + echo "========pipeline execution failed========" + } + } }