From 6865f5f77171d2dc73ab5e62f60e187b63541739 Mon Sep 17 00:00:00 2001 From: Hima2982 <87789349+Hima2982@users.noreply.github.com> Date: Thu, 28 Oct 2021 14:41:23 -0500 Subject: [PATCH 1/2] Create Jenkinsfile --- Jenkinsfile | 93 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 Jenkinsfile diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..28c60f7 --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,93 @@ +pipeline { + + agent { +label 'server_01' +} + +parameters { + string defaultValue: 'master', description: 'This the branch to checkout', name: 'branch_name' + choice choices: ['DEV', 'TEST', 'UAT'], description: 'environment to be deployed', name: 'environment' + booleanparam (name:'executetests',defauiltvalue:true,description :'tests will be executed default' +} + +triggers { + cron '00 20 * * *' +} + +options { + disableConcurrentBuilds() + buildDiscarder logRotator(artifactDaysToKeepStr: '', artifactNumToKeepStr: '', daysToKeepStr: '', numToKeepStr: '10') + timestamps() +} + +tools { + jdk 'JAVA8' + maven 'Maven' +} + +environment { + data_path = "/opt/data/" + SCANNER_HOME =tool 'sonarqube-scanner' +} + + + stages { + + stage ('build') { + steps{ + git branch: '$branch_name', credentialsId: 'github_credentials', url: 'https://github.com/Hima2982/example-java.git' + } + + } + stage ('Test & Scan'){ + parllel{ + stage('unit testing'){ + + when { + expression { + params.executetests == true + } + } + + + steps{ + sh mvn test + script { + gv.buildapp() //external script.groovy is calling here + } + + } + stage('sonarqube testing'){ + + steps { + + withSonarqubeEnv('installationName: 'sonarqube-server'){ + sh "SCANNER_HOME/bin/sonar-scanner -Dproject.settings=sonar-project.properties" + } + } + } + + + } + + } + stage ('deploy'){ + steps{ + mvn package -Dtest.skip=true + } + } + } + + } + +post { + always { + echo "always runs the test from $branch_name" + } + success { + echo "only runs when the test is pass" + } + failure { + echo "only runs when the test is fail" + } +} From 6d792bd906bb6bf6c7999202863826dd7e4dd670 Mon Sep 17 00:00:00 2001 From: Hima2982 <87789349+Hima2982@users.noreply.github.com> Date: Thu, 28 Oct 2021 20:46:51 -0500 Subject: [PATCH 2/2] Update Jenkinsfile --- Jenkinsfile | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 28c60f7..c5ed9ae 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -55,7 +55,7 @@ environment { script { gv.buildapp() //external script.groovy is calling here } - + } } stage('sonarqube testing'){ @@ -63,23 +63,19 @@ environment { withSonarqubeEnv('installationName: 'sonarqube-server'){ sh "SCANNER_HOME/bin/sonar-scanner -Dproject.settings=sonar-project.properties" - } - } + } + } } - - } - - } - stage ('deploy'){ + + stage ('deploy'){ steps{ mvn package -Dtest.skip=true } } } - } - + post { always { echo "always runs the test from $branch_name" @@ -89,5 +85,6 @@ post { } failure { echo "only runs when the test is fail" + } } }