diff --git a/Jenkinsfile b/Jenkinsfile index 7594545d..bea63a50 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,31 +1,41 @@ pipeline { - agent any - environment { - // More detail: - // https://jenkins.io/doc/book/pipeline/jenkinsfile/#usernames-and-passwords - NEXUS_CRED = credentials('nexus') - } + agent any stages { - stage('Build') { + stage('Test') { steps { - echo 'Building..' - sh 'cd webapp && npm install && npm run build' - } + echo 'sonar analysis..' + sh 'cd webapp && sudo docker run --rm -e SONAR_HOST_URL="http://15.207.71.87:9000" -e SONAR_LOGIN="sqp_2a4f79f7274b119b00a43ec599bd49429e6fa9d7" -v ".:/usr/src" sonarsource/sonar-scanner-cli -Dsonar.projectKey=lms' + } } - stage('Test') { + stage('Build & release') { steps { - echo 'Testing..' - sh 'cd webapp && sudo docker container run --rm -e SONAR_HOST_URL="http://20.172.187.108:9000" -e SONAR_LOGIN="sqp_cae41e62e13793ff17d58483fb6fb82602fe2b48" -v ".:/usr/src" sonarsource/sonar-scanner-cli -Dsonar.projectKey=lms' + script { + def packageJSON = readJSON file: 'webapp/package.json' + def packageJSONVersion = packageJSON.version + sh "echo '${packageJSONVersion}'" + + echo 'building..' + sh 'cd webapp && npm install && npm run build' + + echo 'Release..' +sh "zip webapp/dist-'${packageJSONVersion}'.zip -r webapp/dist" +sh "curl -v -u admin:Admin@123 --upload-file webapp/dist-'${packageJSONVersion}'.zip http://15.207.71.87:8081/repository/lms/" + } } } - stage('Release') { + stage('Deploy') { steps { - echo 'Release Nexus' - sh 'rm -rf *.zip' - sh 'cd webapp && zip dist-${BUILD_NUMBER}.zip -r dist' - sh 'cd webapp && curl -v -u $Username:$Password --upload-file dist-${BUILD_NUMBER}.zip http://20.172.187.108:8081/repository/lms/' + script { + def packageJSON = readJSON file: 'webapp/package.json' + def packageJSONVersion = packageJSON.version + echo 'Deploying....' + sh "curl -u admin:Admin@123 -X GET \'http://15.207.71.87: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 diff --git a/webapp/index.html b/webapp/index.html index a683c108..84e96c57 100644 --- a/webapp/index.html +++ b/webapp/index.html @@ -9,7 +9,7 @@ diff --git a/webapp/package.json b/webapp/package.json index c7543640..79295401 100644 --- a/webapp/package.json +++ b/webapp/package.json @@ -1,7 +1,7 @@ { "name": "webapp", "private": true, - "version": "1.0.1", + "version": "2.1", "type": "module", "scripts": { "dev": "vite",