diff --git a/Dockerfile b/Dockerfile index d092e1942..9010f3074 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,9 +1,8 @@ -FROM ubuntu:20.04 as build +FROM ubuntu20.04 RUN apt update && \ - apt install openjdk-17-jdk -y && \ - apt install git -y && \ - git clone https://github.com/spring-projects/spring-petclinic.git && \ + apt install openjdk-11-jdk -y && \ + git clone https://github.com/lahari104/spring-petclinic.git && \ cd spring-petclinic && \ - ./mvnw package + ./mvn package EXPOSE 8080 -CMD [ "java", "-jar", "/spring-petclinic/target/spring-petclinic-3.0.0-SNAPSHOT.jar" ] +CMD [ "java", "-jar", "spring-petclinic" ] \ No newline at end of file diff --git a/Jenkinsfile b/Jenkinsfile index 583d60607..81c27302f 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,25 +1,66 @@ pipeline{ agent{ - label 'docker' + label 'lahari' } triggers{ pollSCM('* * * * *') } parameters{ - choice(name: 'branch_name', choices: ['main', 'two', 'three'], description: 'selecting branch') - } - environment{ - dockerhub_registry_name = "lahari104" - image_name = "spc" + choice(name: 'Branch_Name', choices: ['develop', 'main', 'lahari'], description: 'selecting branch') } stages{ - stage('docker image build'){ + stage('clone'){ steps{ - sh """ - docker image build -t ${image_name}:${BUILD_NUMBER}-${NODE_NAME} . - docker image ls - """ + git url: 'https://github.com/lahari104/spring-petclinic.git', + branch: "${params.Branch_Name}" + } + } + stage('build'){ + steps{ + sh "./mvnw clean package" + } + } + stage('archive_artifacts'){ + steps{ + archiveArtifacts artifacts: '**/target/*.jar' + } + } + stage('junit_reports'){ + steps{ + junit '**/surefire-reports/*.xml' } } } -} + post{ + always{ + echo 'Pipeline is triggered' + mail to: 'goruputivenkatalahari@gmail.com', + subject: 'The pipeline is started', + body: """pipeline is started for $env.BUILD_URL + and the build number is $env.BUILD_NUMBER""" + } + aborted{ + echo 'Pipeline is aborted' + mail to: 'goruputivenkatalahari@gmail.com', + subject: 'The pipeline is aborted', + body: """pipeline is aborted for $env.BUILD_URL + and the build number is $env.BUILD_NUMBER + and jenkins url is $env.JENKINS_URL""" + } + failure{ + echo 'Pipeline is falied' + mail to: 'goruputivenkatalahari@gmail.com', + subject: 'The pipeline is failed', + body: """pipeline is falied for $env.BUILD_URL + and the build number is $env.BUILD_NUMBER + and jenkins url is $env.JENKINS_URL""" + } + success{ + echo 'Pipeline is success' + mail to: 'goruputivenkatalahari@gmail.com', + subject: 'The pipeline is success', + body: """pipeline is success for $env.BUILD_URL + and the build number is $env.BUILD_NUMBER""" + } + } +} \ No newline at end of file diff --git a/azure-spc-pipelines.yaml b/azure-spc-pipelines.yaml new file mode 100644 index 000000000..6a8e3d9f0 --- /dev/null +++ b/azure-spc-pipelines.yaml @@ -0,0 +1,17 @@ +pool: 'Default' +trigger: + - main +stages: + - stage: 'build' + displayName: 'build stage' + jobs: + - job: 'build' + displayName: 'build job' + steps: + - task: Docker@2 + inputs: + containerRegistry: Docker_hub + repository: lahari23/springpetclinic + command: 'buildAndPush' + Dockerfile: '**/Dockerfile' +