From fc4321ee7d48834bbf6996ee2cb01e5ddf904507 Mon Sep 17 00:00:00 2001 From: Anwarullah khan Nuzair Date: Sun, 30 Nov 2025 04:05:18 +0530 Subject: [PATCH] Refactor Jenkinsfile for improved pipeline structure --- Jenkinsfile | 127 ++++++++++++++++++++++++++++++++++------------------ 1 file changed, 83 insertions(+), 44 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index eaa93870..6127af4f 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,45 +1,84 @@ pipeline { - agent any - - stages { - - stage('SonarAnalysis') { - steps { - echo 'SonarAnalysis..' - sh 'cd webapp && sudo docker run --rm -e SONAR_HOST_URL="http://3.12.35.119:9000" -e SONAR_LOGIN="sqp_61675ccbe677383921c6eb020644d0a56cd116c0" -v ".:/usr/src" sonarsource/sonar-scanner-cli -Dsonar.projectKey=lms' - } - } - stage('Build') { - steps { - echo 'Building..' - sh 'cd webapp && npm install && npm run build' - } - } - stage('Release LMS') { - steps { - script { - echo "Releasing.." - def packageJSON = readJSON file: 'webapp/package.json' - def packageJSONVersion = packageJSON.version - echo "${packageJSONVersion}" - sh "zip webapp/dist-${packageJSONVersion}.zip -r webapp/dist" - sh "curl -v -u admin:Admin123* --upload-file webapp/dist-${packageJSONVersion}.zip http://3.12.35.119:8081/repository/lms/" - } - } - } - stage('Deploy') { - steps { - script { - echo "Deploying.." - def packageJSON = readJSON file: 'webapp/package.json' - def packageJSONVersion = packageJSON.version - echo "${packageJSONVersion}" - sh "curl -u admin:Admin123* -X GET \'http://3.12.35.119:8081/repository/lms/dist-${packageJSONVersion}.zip\' --output dist-'${packageJSONVersion}'.zip" - sh 'sudo rm -rf /var/www/html/*' - sh "sudo unzip -o dist-'${packageJSONVersion}'.zip" - sh "sudo cp -r webapp/dist/* /var/www/html" - } - } - } - } -} \ No newline at end of file + agent any + + environment { + SONAR_HOST_URL = "http://44.223.27.240:9000" + SONAR_TOKEN = "squ_ef68f131502f5878f3a9c97d8e88c65100d5d0d5" + NEXUS_URL = "http://44.223.27.240:8081/repository/lms/" + NEXUS_USER = "admin" + NEXUS_PASS = "lms12345" + } + + stages { + + stage('Code Quality') { + steps { + echo 'Sonar Analysis Started' + + sh ''' + docker run --rm \ + -e SONAR_HOST_URL="${SONAR_HOST_URL}" \ + -e SONAR_TOKEN="${SONAR_TOKEN}" \ + -v "$WORKSPACE:/usr/src" \ + sonarsource/sonar-scanner-cli \ + -Dsonar.projectKey=lms + ''' + + echo 'Sonar Analysis Completed' + } + } + + stage('Build LMS') { + steps { + echo 'LMS Build Started' + sh ''' + cd webapp + npm install + npm run build + ''' + echo 'LMS Build Completed' + } + } + + stage('Publish LMS') { + steps { + script { + def packageJson = readJSON file: 'webapp/package.json' + def version = packageJson.version + + sh """ + zip -r lms-${version}.zip webapp/build + curl -v -u ${NEXUS_USER}:${NEXUS_PASS} \ + --upload-file lms-${version}.zip \ + ${NEXUS_URL} + """ + } + } + } + + stage('Deploy LMS') { + steps { + script { + def packageJson = readJSON file: 'webapp/package.json' + def version = packageJson.version + + sh """ + curl -u ${NEXUS_USER}:${NEXUS_PASS} \ + -X GET '${NEXUS_URL}lms-${version}.zip' \ + --output lms-${version}.zip + + sudo rm -rf /var/www/html/* + sudo unzip -o lms-${version}.zip + sudo cp -r webapp/build/* /var/www/html/ + """ + } + } + } + + stage('Clean Up Workspace') { + steps { + cleanWs() + } + } + } +}