diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..c5ed9ae --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,90 @@ +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" + } + } +}