diff --git a/Dockerfile b/Dockerfile index 2cc589c335b..2d82155d31e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,3 +1,8 @@ -FROM tomcat:8 -LABEL app=my-app -COPY target/*.war /usr/local/tomcat/webapps/myweb.war +FROM openjdk:11-jre-slim +WORKDIR /app +COPY target/myweb-0.0.9.war /app/ +CMD ["java", "-jar", "myweb-0.0.9.war"] + + + + diff --git a/Jenkinsfile b/Jenkinsfile index b558a5e4b4a..89d9b646e1e 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,19 +1,47 @@ -@Library("mylibs") _ pipeline { - agent any - tools { - maven 'maven2' - } - stages{ - stage("Maven Build"){ - steps{ - sh "mvn clean package" - } + agent none + + stages { + stage('git checkout') { + agent { + label "maven" + } + steps { + git 'https://github.com/artisenzubair/my-app.git' + } + } + stage('SonarQube Analysis') { + agent { + label "maven" + } + steps { + script { + withSonarQubeEnv('sonarqube') { + withCredentials([string(credentialsId: 'sonarqube', variable: 'SONARQUBE_TOKEN')]) { + sh """mvn clean verify sonar:sonar \ + -Dsonar.projectKey=demo \ + -Dsonar.host.url=http://100.24.253.252:9000 \ + -Dsonar.login=$SONARQUBE_TOKEN""" + } + } + } + } + } + stage('build') { + agent { + label "tomcat" + } + steps { + sh "mvn clean install" + } + } + stage('tomcat') { + agent { + label "tomcat" + } + steps { + sh "cp /home/ubuntu/workspace/assign/target/myweb-0.0.9.war /opt/tomcat/apache-tomcat-9.0.68/webapps/" + } + } } - stage("Deploy To Dev"){ - steps{ - tomcatDeploy("tomcat-dev","ec2-user",["172.31.13.89","172.31.13.89"]) - } } - } -} diff --git a/jenkinsfile.declarative b/jenkinsfile.declarative new file mode 100644 index 00000000000..87c1c08bb6d --- /dev/null +++ b/jenkinsfile.declarative @@ -0,0 +1,48 @@ +pipeline { + agent none + + stages { + stage('git checkout') { + agent { + label "maven" + } + steps { + git 'https://github.com/artisenzubair/my-app.git' + } + } + stage('SonarQube Analysis') { + agent { + label "maven" + } + steps { + script { + withSonarQubeEnv('sonarqube') { + withCredentials([string(credentialsId: 'sonarqube', variable: 'SONARQUBE_TOKEN')]) { + sh """mvn clean verify sonar:sonar \ + -Dsonar.projectKey=demo \ + -Dsonar.host.url=http://100.24.253.252:9000 \ + -Dsonar.login=$SONARQUBE_TOKEN""" + } + } + } + } + } + stage('build') { + agent { + label "tomcat" + } + steps { + sh "mvn clean install" + } + } + stage('tomcat') { + agent { + label "tomcat" + } + steps { + sh "cp /home/ubuntu/workspace/assign/target/myweb-0.0.9.war /opt/tomcat/apache-tomcat-9.0.68/webapps/" + } + } + } + } + diff --git a/jenkinsfile.groovy b/jenkinsfile.groovy new file mode 100644 index 00000000000..053bbb0fb4a --- /dev/null +++ b/jenkinsfile.groovy @@ -0,0 +1,33 @@ +node { + stage('git checkout') { + // Run on an agent labeled "maven" + checkout([$class: 'GitSCM', branches: [[name: '*/master']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[url: 'https://github.com/artisenzubair/my-app.git']]]) + + } + stage('SonarQube Analysis') { + // Run on an agent labeled "maven" + withSonarQubeEnv('sonarqube') { + withCredentials([string(credentialsId: 'sonarqube', variable: 'SONARQUBE_TOKEN')]) { + // Run Maven and SonarQube analysis + sh """mvn clean verify sonar:sonar \ + -Dsonar.projectKey=demo \ + -Dsonar.host.url=http://100.24.253.252:9000 \ + -Dsonar.login=$SONARQUBE_TOKEN""" + } + } + } + stage('build') { + // Run on an agent labeled "tomcat" + node('tomcat') { + // Run Maven build + sh "mvn clean install" + } + } + stage('tomcat') { + // Run on an agent labeled "tomcat" + node('tomcat') { + // Copy the WAR file to Tomcat webapps directory + sh "cp /home/ubuntu/workspace/assign/target/myweb-0.0.9.war /opt/tomcat/apache-tomcat-9.0.68/webapps/" + } + } +} diff --git a/jenkinsfile.new b/jenkinsfile.new new file mode 100644 index 00000000000..a5e53655256 --- /dev/null +++ b/jenkinsfile.new @@ -0,0 +1,11 @@ +pipeline { + agent any + + stages { + stage('git checkout') { + steps { + git 'https://github.com/artisenzubair/my-app.git' + } + } +} +} diff --git a/pom.xml b/pom.xml index 66ca8946c4d..c4a3e246eca 100755 --- a/pom.xml +++ b/pom.xml @@ -41,5 +41,18 @@ 7 1.7 + + + + org.apache.maven.plugins + maven-war-plugin + 3.2.3 + + false + + + + + diff --git a/sonar-status-check b/sonar-status-check index 8f82dc44a33..be266b963f3 100644 --- a/sonar-status-check +++ b/sonar-status-check @@ -43,5 +43,4 @@ node{ teamDomain: 'javahomecloud', tokenCredentialId: 'slack-demo' } - }