diff --git a/Jenkinsfile_AIP b/Jenkinsfile_AIP index 630c2e6..773ef44 100644 --- a/Jenkinsfile_AIP +++ b/Jenkinsfile_AIP @@ -1,10 +1,10 @@ +def propfile pipeline { - - agent { - kubernetes { - label 'SpringBootRestApp' - defaultContainer 'jnlp' - yaml """ + agent { + kubernetes { + label 'SpringBootRestApp' + defaultContainer 'jnlp' + yaml """ apiVersion: v1 kind: Pod metadata: @@ -18,104 +18,154 @@ spec: - cat tty: true """ -} - } - -stages { - stage('Build & Unit Test') { - steps { - container('gradle') { - withMaven(maven: 'MAVEN-3.6.3') { - withSonarQubeEnv(installationName: 'Sonarqube') { - echo 'I am executing unit test' - // sh 'for i in ESBAuditClient ESBAuditLog ESBErrorTranslator TaxESB FraudESB FulfillmentESB PaymentESB ESBRadial ESBAutomatedQueueRetry AlertESB OrderReconESB;do gradle --no-daemon -p ${i} clean build;done' - sh 'mvn -f sample-java-app/pom.xml clean package' + } + } + environment { + GRADLE_PATH = '/opt/gradle/gradle-3.5.1/bin' + GRADLE_TASK = 'ESBAuditClient ESBAuditLog ESBErrorTranslator TaxESB FraudESB FulfillmentESB PaymentESB ESBRadial ESBAutomatedQueueRetry AlertESB OrderReconESB' + DEPLOYMENT_ARCHIVE_DIR='/home/muleadmin/stage/archive' + DEPLOYMENT_STAGE_DIR='/home/muleadmin/stage' + DEPLOYMENT_DIR='/opt/mule/latest/webapps' + WAR_FILES='AlertESB.war FraudESB.war TaxESB.war PaymentESB.war FulfillmentESB.war ESBAuditLog.war ESBAutomatedQueueRetry.war OrderReconESB.war' + ESB_BIN_PATH='/opt/mule/bin/esb_service' + ESB_WAR_FOLDERS='PaymentESB ESBAuditLog OrderReconESB FraudESB TaxESB FulfillmentESB AlertESB ESBAutomatedQueueRetry' + REQUESTID='779' + STAGE_NAME='dev3' + WORKSOFT_URI='http://pwwsftapp01/executionmanager/api' + USERNAME='devopsengineering@signetjewelers.com' + USERNAME_FEATURE_DEPLOY='muleadmin' + HOSTS_FEATURE_DEPLOY="10.6.74.90" + USERNAME_DEV_DEPLOY='muleadmin' + HOSTS_DEV_DEPLOY="10.6.74.91, 10.6.74.92" + USERNAME_RELEASE='muleadmin' + HOSTS_RELEASE_DEPLOY="10.6.74.93, 10.6.74.94" + } + stages { + stage('Build & Unit Test') { + steps { + container('gradle') { + script { + withMaven(maven: 'MAVEN-3.6.3') { + echo 'I am executing build and unit test' + echo "Use the line below when we switch to the actual repo" + // sh 'for i in ESBAuditClient ESBAuditLog ESBErrorTranslator TaxESB FraudESB FulfillmentESB PaymentESB ESBRadial ESBAutomatedQueueRetry AlertESB OrderReconESB;do gradle --no-daemon -p ${i} clean build;done' + echo "Remove the line below when we switch to the actual repo" + sh 'mvn -f sample-java-app/pom.xml clean package' + propfile = readProperties(file: './project.properties') + if (propfile['javadoc'] == "true") { + sh 'mvn javadoc:aggregate' + } + if (propfile['jacoco'] == "true") { + jacoco( + execPattern: '**/*.exec', + classPattern: '**/*.class', + sourcePattern: '**/*.java', + exclusionPattern: '**/test*' + ) + } + } } } } } - } - stage('Code Quality') { - steps { - container('gradle') { - withMaven(maven: 'MAVEN-3.6.3') { - withSonarQubeEnv(installationName: 'Sonarqube') { + /* stage('Code Quality') { + steps { + container('gradle') { + withMaven(maven: 'MAVEN-3.6.3') { + withSonarQubeEnv(installationName: 'Sonarqube') { echo 'I am executing code quality using sonarqube' - sh 'mvn -f sample-java-app/pom.xml sonar:sonar' + echo ' Update the line below when we switch to actual ESB repo' + // sh './gradle Sonarqube' + echo ' Remove the line below after we switch to ESB repo' + sh 'mvn -f sample-java-app/pom.xml -Dsonar.projectName=ESB_${BRANCH_NAME} -Dsonar.projectKey=ESB_sample sonar:sonar' + } + sleep(60) + timeout(time: 1, unit: 'MINUTES') { + waitForQualityGate abortPipeline: true + } } - /* sleep(60) - timeout(time: 1, unit: 'MINUTES') { - waitForQualityGate abortPipeline: true - } */ } } - } - } - stage("Publish Package") { - steps { - container('gradle') { - script { - propfile = readProperties(file: './project.properties') - println("deploy:" + propfile['feature_deploy']) - println("reading properties ...") - if (propfile['feature_deploy'] == "true" || env.BRANCH_NAME == 'dev' || env.BRANCH_NAME == 'release') { - withMaven(maven: 'MAVEN-3.6.3') { + } */ + stage("Publish Package") { + when { expression {env.GIT_BRANCH == 'origin/dev' || env.GIT_BRANCH == 'origin/release'|| propfile['feature_deploy'] == "true" }} + steps { + container('gradle') { + script { + withMaven(maven: 'MAVEN-3.6.3') { echo 'I am pushing the artifact with unique name showing the branch from which it is generated, to Archiva' + echo 'Replace the next 4 lines to reflect the ESB artifact and push it to archiva' + echo 'Use the 5 lines below when we switch to the actual ESB repo' /* echo 'copying the jar and war files from the individual target directorrys and copying it to artifacts directory ' sh "mkdir -p $WORKSPACE/artifacts" - sh 'for i in ESBAuditClient ESBAuditLog ESBErrorTranslator TaxESB FraudESB FulfillmentESB PaymentESB ESBRadial ESBAutomatedQueueRetry AlertESB OrderReconESB;do cp -rp ${i}/dist/libs/* $WORKSPACE/artifacts/ ;done' */ - /* echo 'create a tar file on the Jenkins server' - sh "cd $WORKSPACE/artifacts/ && tar -cvzf artifact.tar * && md5sum artifact.tar archiveArtifacts artifacts: 'artifacts/*.tar', fingerprint: true */ + sh 'for i in ESBAuditClient ESBAuditLog ESBErrorTranslator TaxESB FraudESB FulfillmentESB PaymentESB ESBRadial ESBAutomatedQueueRetry AlertESB OrderReconESB;do cp -rp ${i}/dist/libs/* $WORKSPACE/artifacts/ ;done' + echo 'create a tar file on the Jenkins server' + sh "cd $WORKSPACE/artifacts/ && tar -cvzf artifact.tar * && md5sum artifact.tar archiveArtifacts artifacts: 'artifacts/*.tar', fingerprint: true + */ + echo 'Remove the below 3 lines after switching to the actual ESB repo' sh 'mv sample-java-app/target/sample-0.0.1-SNAPSHOT.jar sample-java-app/target/sample-build_${BUILD_NUMBER}-branch_${BRANCH_NAME}.jar' sh 'ls -lrt sample-java-app/target/' - sh 'mvn -X deploy:deploy-file -Dfile=sample-java-app/target/sample-build_${BUILD_NUMBER}-branch_${BRANCH_NAME}.jar -DpomFile=sample-java-app/pom.xml -DrepositoryId=snapshots -Durl=https://archiva.sgn.devops.accentureanalytics.com/repository/snapshots/' - echo "noooooooooooooooooo" + sh 'mvn -X deploy:deploy-file -Dfile=sample-java-app/target/sample-build_${BUILD_NUMBER}-branch_${BRANCH_NAME}.jar -DpomFile=sample-java-app/pom.xml -DrepositoryId=snapshots -Durl=https://archiva.sgn.devops.accentureanalytics.com/repository/snapshots/' } } } } } - } - stage("Deploy") { - steps { - container('gradle') { - script { - propfile = readProperties(file: './project.properties') - println("deploy:" + propfile['feature_deploy']) - println("reading properties ...") - if (propfile['feature_deploy'] == "true" || env.BRANCH_NAME == 'dev' || env.BRANCH_NAME == 'release') { - withMaven(maven: 'MAVEN-3.6.3') { - echo 'I am deploying the artifact into the target environment' - echo 'shutting down the tomcat ESB server' - /* sh 'ssh $DEPLOYMENT_USER@$DEPOYMENT_SERVER "$ESB_BIN_PATH stop || sleep 20"' - echo 'force stop any remaining mule process' - sh 'ssh $DEPLOYMENT_USER@$DEPOYMENT_SERVER "if [[ $(ps aux | grep /opt/mule/latest/ | grep -vc grep) > 0 ]]; then "kill -9 $(ps -ef|pgrep -f "/opt/mule/latest/bin")"; else echo "do nothing"; fi"' */ - echo 'tomcat server stopped' - echo 'copying the tar file from jenkins to deployment directory on app and remove the old folders and untarring the new jar and war files' - /* sh 'scp -rp $WORKSPACE/artifacts/artifact.tar $DEPLOYMENT_USER@$DEPOYMENT_SERVER:$DEPLOYMENT_STAGE_DIR/' - sh 'ssh $DEPLOYMENT_USER@$DEPOYMENT_SERVER "cd $DEPLOYMENT_STAGE_DIR && rm -rf *.war *.jar"' - sh 'ssh $DEPLOYMENT_USER@$DEPOYMENT_SERVER "cd $DEPLOYMENT_STAGE_DIR && tar -xvzf artifact.tar && rm -rf *.jar"' - sh 'ssh $DEPLOYMENT_USER@$DEPOYMENT_SERVER "cd $DEPLOYMENT_DIR && rm -rf $ESB_WAR_FOLDERS && cp -rp $DEPLOYMENT_STAGE_DIR/*.war $DEPLOYMENT_DIR"' */ - echo 'Deployment has been completed' - echo 'starting the tomcat ESB server' - /* sh 'ssh $DEPLOYMENT_USER@$DEPOYMENT_SERVER "$ESB_BIN_PATH start"' - sh 'ssh $DEPLOYMENT_USER@$DEPOYMENT_SERVER "sleep 20"' */ - echo 'tomcat server started' - } - } else { - echo "no need" + stage("Deploy") { + when { expression {env.GIT_BRANCH == 'origin/dev' || env.GIT_BRANCH == 'origin/release'|| propfile['feature_deploy'] == "true" }} + steps { + container('gradle') { + script { + withMaven(maven: 'MAVEN-3.6.3') { + if (propfile['feature_deploy'] == "true" ) { + USERNAME=env.USERNAME_FEATURE_DEPLOY + HOSTS=env.HOSTS_FEATURE_DEPLOY + } + if (env.BRANCH_NAME == 'dev' ) { + USERNAME=env.USERNAME_DEV_DEPLOY + HOSTS=env.HOSTS_DEV_DEPLOY + } + if (env.BRANCH_NAME == 'release') { + USERNAME=env.USERNAME_RELEASE_DEPLOY + HOSTS=env.HOSTS_RELEASE_DEPLOY + } + HOSTS.tokenize(',').each { HOSTNAME -> + echo "I am deploying the artifact into the target environment ${HOSTNAME} as user ${USERNAME}" + echo 'Replace all the lines below for ESB and add the parameters to propfile and make refrences below' + echo 'Accom logic for multiple env and mult servers in each env based on the branch name' + echo 'shutting down the tomcat ESB server' + /* sh 'ssh ${USERNAME}@${HOSTNAME} "$ESB_BIN_PATH stop || sleep 20"' + echo 'force stop any remaining mule process' + sh 'ssh ${USERNAME}@${HOSTNAME} "if [[ $(ps aux | grep /opt/mule/latest/ | grep -vc grep) > 0 ]]; then "kill -9 $(ps -ef|pgrep -f "/opt/mule/latest/bin")"; else echo "do nothing"; fi"' + */ + echo 'tomcat server stopped' + echo 'copying the tar file from jenkins to deployment directory on app and remove the old folders and untarring the new jar and war files' + /* sh 'scp -rp $WORKSPACE/artifacts/artifact.tar $DEPLOYMENT_USER@$DEPOYMENT_SERVER:$DEPLOYMENT_STAGE_DIR/' + sh 'ssh ${USERNAME}@${HOSTNAME} "cd $DEPLOYMENT_STAGE_DIR && rm -rf *.war *.jar"' + sh 'ssh ${USERNAME}@${HOSTNAME} "cd $DEPLOYMENT_STAGE_DIR && tar -xvzf artifact.tar && rm -rf *.jar"' + sh 'ssh ${USERNAME}@${HOSTNAME} "cd $}DEPLOYMENT_DIR} && rm -rf ${ESB_WAR_FOLDERS} && cp -rp ${DEPLOYMENT_STAGE_DIR}/*.war $DEPLOYMENT_DIR"' + */ + echo 'Deployment has been completed' + echo 'starting the tomcat ESB server' + /* sh 'ssh ${USERNAME}@${HOSTNAME} "${ESB_BIN_PATH start}"' + sh 'ssh ${USERNAME}@${HOSTNAME} "sleep 20"' + */ + echo 'tomcat server started' + } + } } } } } - } - stage('Post Deploy Tests') { + + + stage('Post Deploy Tests') { parallel { stage('Smoke Test') { steps { echo "I am executing Smoke Test on target dev environment post deployment" } - /*RESP=`curl -X GET "${bamboo.uri}/RequestsRunning" -H "accept: application/xml" -H "authorization: bearer lR0AA2qfq7v9Ry96vDAgqcer1GPVd5yStmv1_aJVFS43rk06EytB7WsS0_owoiXIgpOXmZVEfkY4ST0JwHtRBk7RH0QRaldWtQT8udC0VdimdGx38RddY2sGaeeF0t9Aflr5rh1Jc_EUfkNK8YrKVxQ6kxB05aCe46CD2fkognv7TiJATmht-ycUjEsd_oy8jH5EK9fmn9eL-wXavNTQcEdsUmFm3-2r3IJDzMK7XCa74qu353yOKLvVyZ1yYQBnc1_fY5GS1BDrFLUZprxpAS30lGEu-d_JTTOQ989UJtIEB3cZzDkIQzeqdYBGCsiDdjdHo2DC1FK2kVPyBITTbQ"` + /*RESP=`curl -X GET "${WORKSOFT_URI}/RequestsRunning" -H "accept: application/xml" -H "authorization: bearer lR0AA2qfq7v9Ry96vDAgqcer1GPVd5yStmv1_aJVFS43rk06EytB7WsS0_owoiXIgpOXmZVEfkY4ST0JwHtRBk7RH0QRaldWtQT8udC0VdimdGx38RddY2sGaeeF0t9Aflr5rh1Jc_EUfkNK8YrKVxQ6kxB05aCe46CD2fkognv7TiJATmht-ycUjEsd_oy8jH5EK9fmn9eL-wXavNTQcEdsUmFm3-2r3IJDzMK7XCa74qu353yOKLvVyZ1yYQBnc1_fY5GS1BDrFLUZprxpAS30lGEu-d_JTTOQ989UJtIEB3cZzDkIQzeqdYBGCsiDdjdHo2DC1FK2kVPyBITTbQ"` echo "The response for current execution status is: $RESP" if [ "$RESP" != "[]" ]; then @@ -125,20 +175,20 @@ stages { echo "There are no tests executing right now. Hence, proceeding with Worksoft test execution" fi # To abort the request before attempting to re-run, uncomment and run below line. - # abort=$(curl -X PUT -H "Authorization: Bearer $token" -d "" -H "id: ${bamboo.RequestID}" ${bamboo.uri}/Request/${bamboo.RequestID}/abort/) - guid=$(curl -X PUT -H "Authorization: Bearer $token" -d "" -H "parameters: {TestEnv}{${bamboo.stage_name}}" -H "id: ${bamboo.RequestID}" ${bamboo.uri}/ExecuteRequest/ | tr -d \") + # abort=$(curl -X PUT -H "Authorization: Bearer $token" -d "" -H "id: ${REQUESTID}" ${WORKSOFT_URI}/Request/${REQUESTID}/abort/) + guid=$(curl -X PUT -H "Authorization: Bearer $token" -d "" -H "parameters: {TestEnv}{${STAGE_NAME}}" -H "id: ${REQUESTID}" ${WORKSOFT_URI}/ExecuteRequest/ | tr -d \") echo "The GUID is: $guid" - status=$(curl -X GET -H "Authorization: Bearer $token" -d "" -H "APIRequestID: $guid" ${bamboo.uri}/ExecutionStatus/ | awk -F':' '{print $2}' | tr -d \" | tr -d \}) + status=$(curl -X GET -H "Authorization: Bearer $token" -d "" -H "APIRequestID: $guid" ${WORKSOFT_URI}/ExecutionStatus/ | awk -F':' '{print $2}' | tr -d \" | tr -d \}) echo "The status is: $status" while [[ $status != *"Completed"* ]] do - status=$(curl -X GET -H "Authorization: Bearer $token" -d "" -H "APIRequestID: $guid" ${bamboo.uri}/ExecutionStatus/ | awk -F':' '{print $2}' | tr -d \" | tr -d \}) + status=$(curl -X GET -H "Authorization: Bearer $token" -d "" -H "APIRequestID: $guid" ${WORKSOFT_URI}/ExecutionStatus/ | awk -F':' '{print $2}' | tr -d \" | tr -d \}) echo "The status is: $status" sleep 15 done - status=$(curl -X GET -H "Authorization: Bearer $token" -d "" -H "APIRequestID: $guid" ${bamboo.uri}/ExecutionStatus/) + status=$(curl -X GET -H "Authorization: Bearer $token" -d "" -H "APIRequestID: $guid" ${WORKSOFT_URI}/ExecutionStatus/) echo "The status is: $status" - execstatus=$(curl -X GET -H "Authorization: Bearer $token" -d "" -H "APIRequestID: $guid" ${bamboo.uri}/ExecutionStatus/ | awk -F':' '{print $3}' | tr -d \" | tr -d \}) + execstatus=$(curl -X GET -H "Authorization: Bearer $token" -d "" -H "APIRequestID: $guid" ${WORKSOFT_URI}/ExecutionStatus/ | awk -F':' '{print $3}' | tr -d \" | tr -d \}) echo "The exec status is: $execstatus" if [[ $execstatus != *Passed* ]]; then @@ -152,27 +202,42 @@ stages { } stage('Security Test') { steps { - echo 'I am running Security Test here' - } - } - } - } - } - post { - failure { - /*mail bcc: '', - body: "Example
\n
Project: ${env.JOB_NAME}
Build Number: ${env.BUILD_NUMBER}
URL de build: ${env.BUILD_URL}", - cc: '', - charset: 'UTF-8', - from: '', - mimeType: 'text/html', - replyTo: '', - subject: "ERROR CI: Project name -> ${env.JOB_NAME}", - to: "foo@foomail.com";*/ - echo 'I am sending a notification with failure' - } - success { - echo 'I am sending a notification with success' + container('gradle') { + script { + withMaven(maven: 'MAVEN-3.6.3') { + echo 'I am running Security Test here' + } + } + } + } + } + } } - } + + } + + post { + always { + script { + if (propfile['javadoc'] == "true") { + javadoc(javadocDir: "/$WORKSPACE/target/site/apidocs", keepAll: true) + } + } + } + failure { + /*mail bcc: '', + body: "Example
\n
Project: ${env.JOB_NAME}
Build Number: ${env.BUILD_NUMBER}
URL de build: ${env.BUILD_URL}", + cc: '', + charset: 'UTF-8', + from: '', + mimeType: 'text/html', + replyTo: '', + subject: "ERROR CI: Project name -> ${env.JOB_NAME}", + to: "foo@foomail.com";*/ + echo 'I am sending a notification with failure' + } + success { + echo 'I am sending a notification with success' + } + } } diff --git a/project.properties b/project.properties index 76c7318..1c7df16 100644 --- a/project.properties +++ b/project.properties @@ -1,2 +1,4 @@ feature_deploy=false servers=lxapp.2378 lxapp.656 lxapp.5376 +javadoc=true +jacoco=true diff --git a/sample-java-app/pom.xml b/sample-java-app/pom.xml index 4b589c0..43aaa8d 100644 --- a/sample-java-app/pom.xml +++ b/sample-java-app/pom.xml @@ -68,6 +68,54 @@ 4.5.3 + + + org.jacoco + jacoco-maven-plugin + 0.8.3 + + + jacoco-initialize + + prepare-agent + + + + jacoco-report + test + + report + + + + + coverage-check + + check + + + target/jacoco-report + ${project.build.directory}/coverage-reports/jacoco.exec + + + CLASS + + com.asimio.demo.Application + + + + LINE + COVEREDRATIO + 80% + + + + + + + + +