diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..1ba5c19c2 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,14 @@ +# Use official Tomcat base image +FROM tomcat:9.0 + +# Remove default webapps (optional) +RUN rm -rf /usr/local/tomcat/webapps/* + +# Copy your WAR file into the webapps directory +COPY **/*.war /usr/local/tomcat/webapps/ROOT.war + +# Expose the default Tomcat port +EXPOSE 8080 + +# Start Tomcat +CMD ["catalina.sh", "run"] \ No newline at end of file diff --git a/jenkinsfile1 b/jenkinsfile1 new file mode 100644 index 000000000..e4837571d --- /dev/null +++ b/jenkinsfile1 @@ -0,0 +1,83 @@ +pipeline +{ + agent any + tools{ + maven "MAVEN_HOME" + jdk "JAVA-17" + } + environment{ + GIT_URL="https://github.com/DevopsTech12/vprofile-project.git" + ECR_REPO = "https://279684396313.dkr.ecr.ap-south-1.amazonaws.com/vprofileapp" + IMAGE_NAME = 'vprofileapp' + } + stages{ + stage("scm chekout") + { + steps{ git branch: 'local', url: "$GIT_URL" } + } + stage("test") + { + steps{sh 'mvn test'} + } + stage("build artifact") + { + steps{sh 'mvn package -Dskiptest'} + post{ + success{ + echo "archiving artifact" + sleep 10 + archiveArtifacts artifacts: '**/*.war' + } + } + } + stage("checkstyle checks") + { + steps{sh 'mvn checkstyle:checkstyle'} + } + + // stage("sonar qube analysis") + // { + // steps{ withSonarQubeEnv(credentialsId: 'SonarToken', installationName: 'SonarServer') { + // sh 'mvn sonar:sonar' +//}} + stage('docker image build') + { + steps { + script { + dockerImage = docker.build("${IMAGE_NAME}:latest") + } + } + } + stage ('push image to ECR') + { + steps{ + // This step should not normally be used in your script. Consult the inline help for details. + withDockerRegistry(credentialsId: 'ecr:ap-south-1:ecrcred', url: "${ECR_REPO}") { + sh "docker push ${IMAGE_NAME}:latest" + //sh "docker push ${ECR_REPO}:latest" + } + // sh "docker push ${ECR_REPO}:latest" + } + } + } + + post { + success { + slackSend channel: '#devops', + color: '#439FE0', + message: "✅ *Build SUCCESS* for Job: `${env.JOB_NAME}` Build: #${env.BUILD_NUMBER}\n<${env.BUILD_URL}|Open Build>", + teamDomain: 'vbtech-workspace', + tokenCredentialId: 'Slack-Jenkins' + + } + failure { + slackSend channel: '#devops', + color: '#FF0000', + message: "❌ *Build FAILED* for Job: `${env.JOB_NAME}` Build: #${env.BUILD_NUMBER}\n<${env.BUILD_URL}|Check Console>", + teamDomain: 'vbtech-workspace', + tokenCredentialId: 'Slack-Jenkins' + + } + } +} + \ No newline at end of file diff --git a/jenkinsfile2 b/jenkinsfile2 new file mode 100644 index 000000000..43399ef9a --- /dev/null +++ b/jenkinsfile2 @@ -0,0 +1,28 @@ +pipeline{ + agent any + tools { + maven 'MAVEN_HOME' + java 'JAVA_HOME' + } + environment{ + GIT_URL="https://github.com/DevopsTech12/vprofile-project.git" + + } + stages{ + stage('scm checkout') + steps{git branch: 'local', url: "$GIT_URL" + } + stage('Testing') + steps{sh 'mvn test' + + } + stage('build artifact') + steps{sh 'mvn clean package -Dskiptest'} + post{ + success{slackSend channel: '#artifact', message: '"✅ *Artifact build* for Job: `${env.JOB_NAME}` Build: #${env.BUILD_NUMBER}\\n<${env.BUILD_URL}|Open Build>"', teamDomain: 'vbtech-workspace', tokenCredentialId: 'artifact-slack-jenkins' + + } + } + + } +} \ No newline at end of file diff --git a/pom.xml b/pom.xml index 70aeac29d..9fa19b2b3 100644 --- a/pom.xml +++ b/pom.xml @@ -272,6 +272,11 @@ maven-war-plugin 3.4.0 + + org.apache.maven.plugins + maven-surefire-plugin + 3.1.2 + org.jacoco