diff --git a/Jenkinsfile b/Jenkinsfile index 7594545d..140fdb7d 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,31 +1,37 @@ pipeline { agent any - environment { - // More detail: - // https://jenkins.io/doc/book/pipeline/jenkinsfile/#usernames-and-passwords - NEXUS_CRED = credentials('nexus') - } stages { - stage('Build') { + + stage('Build & Release') { steps { - echo 'Building..' + 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 'Releasing' + sh "zip webapp/dist-'${packageJSONVersion}'.zip -r webapp/dist" + sh "curl -v -u admin:Admin123* --upload-file webapp/dist-'${packageJSONVersion}'.zip http://18.219.166.107:8081/repository/lms/" + } } } - stage('Test') { - 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' - } - } - 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:Admin123* -X GET \'http://18.219.166.107: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 +}