diff --git a/Empty_file b/Empty_file new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/Empty_file @@ -0,0 +1 @@ + diff --git a/Jenkinsfile b/Jenkinsfile index 61d84f7..327d887 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,30 +1,76 @@ pipeline { - agent any + agent { label 'dev' } // Specify the label of your Jenkins Slave. Modify 'dev' if you use a different label. + + environment { + MAVEN_HOME = tool name: 'Maven' // Ensure 'Maven' matches the name in Jenkins tool configuration. + SONARQUBE_SERVER = 'Sonar' // Define the SonarQube server ID. + SONAR_SCANNER_HOME = tool name: 'SonarScanner' // Ensure 'SonarScanner' matches the name in Jenkins tool configuration. + ARTIFACTORY_SERVER = 'Artifactory' // Define Artifactory server ID. + SONAR_TOKEN = 'sqa_bcb97e97554c1eeff5b2a5cd9c0a23d2d59b749b' // SonarQube token + } + stages { - stage ('checkout') { + stage('Checkout') { steps { - echo "This is checkout stage" + // Checkout the source code from your repository + git url: 'https://github.com/shashank1553/java-onlinebookstore.git', branch: 'main' } } - stage ('build') { + + stage('Build') { steps { - echo "This is build stage " + // Build the Maven project + sh "${MAVEN_HOME}/bin/mvn clean install" } } - stage ('sonarscan') { + + stage('SonarQube Analysis') { steps { - echo "This is sonarscan stage " + // Run SonarQube analysis + withSonarQubeEnv(SONARQUBE_SERVER) { + sh "${MAVEN_HOME}/bin/mvn sonar:sonar -Dsonar.login=${SONAR_TOKEN}" + } } - } - stage ('push') { + } + + stage('Deploy to Artifactory') { steps { - echo "This is push stage" + script { + // Upload artifacts to JFrog Artifactory + rtUpload ( + serverId: ARTIFACTORY_SERVER, + spec: '''{ + "files": [{ + "pattern": "target/onlinebookstore.war", // Path to the artifact to upload + "target": "maven-releases/onlinebookstore/" // Target repository path in Artifactory + }] + }''' + ) + } } } - stage ('deploy') { + + stage('Deploy to Tomcat') { steps { - echo "This is deploy stage " + script { + // Deploy the WAR file to Apache Tomcat server + sh """ + curl -u admin:Admin12345 --upload-file target/onlinebookstore.war "http://35.171.26.114:8081/artifactory/maven-releases/onlinebookstore/" + """ + } } - } + } + } + + post { + always { + cleanWs() // Clean the workspace after the build + } + success { + echo "Build, Analysis, and Deployment succeeded!" + } + failure { + echo "Build failed. Check the logs!" + } } } diff --git a/pom.xml b/pom.xml index 4eeeb4f..eb75375 100644 --- a/pom.xml +++ b/pom.xml @@ -1,75 +1,80 @@ - 4.0.0 - onlinebookstore - onlinebookstore - 0.0.1-SNAPSHOT - war - - src/main/java - onlinebookstore - - - org.apache.maven.plugins - maven-dependency-plugin - 2.3 - - - package - - copy - - - - - com.github.jsimone - webapp-runner - 8.0.30.2 - webapp-runner.jar - - - - - - - - maven-compiler-plugin - 3.11.0 - - 1.8 - 1.8 - - - - maven-war-plugin - 3.2.1 - - WebContent - - - - - + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + 4.0.0 + onlinebookstore + onlinebookstore + 0.0.1-SNAPSHOT + war + + + src/main/java + onlinebookstore + + + org.apache.maven.plugins + maven-dependency-plugin + 3.6.0 + + + package + + copy + + + + + com.github.jsimone + webapp-runner + 8.0.30.2 + webapp-runner.jar + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.11.0 + + 1.8 + 1.8 + + + + org.apache.maven.plugins + maven-war-plugin + 3.3.1 + + src/main/webapp + + + + org.sonarsource.scanner.maven + sonar-maven-plugin + 4.0.0.4121 + + + - - org.postgresql - postgresql - 42.3.7 - - - - - mysql - mysql-connector-java - 8.0.28 - - - - - javax.servlet - javax.servlet-api - 3.1.0 - - - \ No newline at end of file + + + org.postgresql + postgresql + 42.3.7 + + + mysql + mysql-connector-java + 8.0.28 + + + javax.servlet + javax.servlet-api + 4.0.1 + provided + + +