diff --git a/Dockerfile b/Dockerfile index e39ef3a..e3bb8b5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ FROM openjdk -COPY target/*.jar / -EXPOSE 8080 -ENTRYPOINT ["java","-jar","/my-app-1.0-SNAPSHOT.jar"] \ No newline at end of file +COPY target/*.jar . +EXPOSE 9000 +ENTRYPOINT ["java","-cp","/my-app-1.0-SNAPSHOT.jar","com.mycompany.app.App"] diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..8e2eb5b --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,132 @@ +pipeline { + // environment { + //registry = "akash64574/myapp" + //registryCredential = 'dockerhub' + //dockerImage = '' + // } +agent any + +stages { + +stage('SCM Checkout') { + steps { + checkout scm + // git 'https://github.com/akash64574/maven-hello-world' +} +} + +stage('Build') { +steps { + sh"/opt/maven/bin/mvn clean package " +} +} +stage("build & SonarQube analysis") { + + steps { + withSonarQubeEnv('sonar') { + sh '/opt/maven/bin/mvn sonar:sonar' + } + } + } + //stage("Quality Gate") { + //steps { + //timeout(time: 1, unit: 'MINUTES') { + //waitForQualityGate abortPipeline: true + //} + //} + //} + + + stage("testing") { + when { + branch 'QA' + } + steps { + + sh '/opt/maven/bin/mvn cobertura:cobertura -Pmetrics -Dcobertura.report.format=xml' + cobertura autoUpdateHealth: false, autoUpdateStability: false, coberturaReportFile: '**/target/site/cobertura/coverage.xml', conditionalCoverageTargets: '70, 0, 0', enableNewApi: true, failNoReports: false, failUnhealthy: false, failUnstable: false, lineCoverageTargets: '80, 0, 0', maxNumberOfBuilds: 0, methodCoverageTargets: '80, 0, 0', onlyStable: false, sourceEncoding: 'ASCII', zoomCoverageChart: false + sh '/opt/maven/bin/mvn verify' + junit allowEmptyResults: true, testResults: '**/target/surefire-reports/*.xml' + } + } + stage ('Notify Dev'){ + steps { + slackSend baseUrl: 'https://hooks.slack.com/services/', channel: 'jenkins_dev', message: 'Build and Testing completed Deployment is under process , please wait for further notification ', teamDomain: '$WORKSPACE', tokenCredentialId: 'slack', username: 'Akash' + } + } + stage('Build Docker Image') { + steps { + script { + sh 'docker build -t akash64574/my-app-1.0 .' + } + } + } + stage ('Notify qa'){ + steps { + slackSend baseUrl: 'https://hooks.slack.com/services/', channel: 'jenkins_qa', message: 'Build and Testing completed and status is good , Deployment is pending for approval', teamDomain: '$WORKSPACE', tokenCredentialId: 'slackqa', username: 'Akash' + } + } + stage( 'Appoval mail for QA' ){ + steps{ + slackSend baseUrl: 'https://hooks.slack.com/services/', channel: 'jenkins_qa', message: "${env.BUILD_URL}", teamDomain: '', tokenCredentialId: 'slackqa' + } +} + + stage("QA Approval") { + steps { + +script { +def userInput = input(id: 'Proceed1', message: 'Promote build?', parameters: [[$class: 'BooleanParameterDefinition', defaultValue: true, description: '', name: 'Please confirm you agree with this']]) +echo 'userInput: ' + userInput + + if(userInput == true) { + // do action + } else { + // not do action + echo "Action was aborted." + } + + } + + } + } + stage('Push Docker Image') { + steps { + script { + withCredentials([string(credentialsId: 'dockerhub-pwd', variable: 'dockerhubpwd')]) { + sh 'docker login -u akash64574 -p ${dockerhubpwd}' + } + sh 'docker push akash64574/my-app-1.0' + } + } + } + stage ('Notify Dev again'){ + steps { + slackSend baseUrl: 'https://hooks.slack.com/services/', channel: 'jenkins_dev', message: 'Your Deployment is completed :-)', teamDomain: '$WORKSPACE', tokenCredentialId: 'slack', username: 'Akash' + } + } + stage ('Notify qa again'){ + when { + branch 'QA' + } + steps { + slackSend baseUrl: 'https://hooks.slack.com/services/', channel: 'jenkins_qa', message: 'Your Deployment is successfully completed !!', teamDomain: '$WORKSPACE', tokenCredentialId: 'slackqa', username: 'Akash' + } + } + stage ('email notification'){ + when { + branch 'Dev' + } + steps { + + emailext body: '''Hi Dev Team + Your deployment is successful !! + Regards + QA Team ''', subject: 'Jenkins Job status', to: 'snarang601@gmail.com' + + } + } + + + } +} diff --git a/Test.xml b/Test.xml new file mode 100644 index 0000000..3acf3ac --- /dev/null +++ b/Test.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/src/test/java/com/mycompany/app/AppTest.java b/src/test/java/com/mycompany/app/AppTest.java index 81ac345..0cb942c 100644 --- a/src/test/java/com/mycompany/app/AppTest.java +++ b/src/test/java/com/mycompany/app/AppTest.java @@ -15,6 +15,11 @@ public class AppTest @Test public void shouldAnswerWithTrue() { - assertTrue( true ); + + //comment the above 2 lines and uncomment below 2 lines to use Chrome + //System.setProperty("webdriver.chrome.driver","G:\\chromedriver.exe"); + + + assertTrue( true ); } }