From 5caff5b075777d332db32c7df2cd302a075615d0 Mon Sep 17 00:00:00 2001 From: amadinathaniel Date: Thu, 21 Apr 2022 11:29:46 +0100 Subject: [PATCH 01/12] Create Jenkinsfile --- Jenkinsfile | 1 + 1 file changed, 1 insertion(+) create mode 100644 Jenkinsfile diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 000000000..8b1378917 --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1 @@ + From 36bed208d0ccb6ce9f20e72168c14a0e9db66ab2 Mon Sep 17 00:00:00 2001 From: amadinathaniel Date: Thu, 21 Apr 2022 11:52:23 +0100 Subject: [PATCH 02/12] Update .env.sample --- .env.sample | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.env.sample b/.env.sample index 1c39502a5..c554f72b6 100644 --- a/.env.sample +++ b/.env.sample @@ -3,7 +3,7 @@ APP_DEBUG=true APP_KEY=SomeRandomString APP_URL=http://localhost -DB_HOST=127.0.0.1 +DB_HOST=172.31.45.156 DB_DATABASE=homestead DB_USERNAME=homestead DB_PASSWORD=sePret^i @@ -21,4 +21,4 @@ MAIL_HOST=mailtrap.io MAIL_PORT=2525 MAIL_USERNAME=null MAIL_PASSWORD=null -MAIL_ENCRYPTION=null \ No newline at end of file +MAIL_ENCRYPTION=null From ff9ce72d4fe12e8ecd808c08850feb2408485d2d Mon Sep 17 00:00:00 2001 From: amadinathaniel Date: Thu, 21 Apr 2022 15:28:02 +0100 Subject: [PATCH 03/12] Update .env.sample --- .env.sample | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.env.sample b/.env.sample index c554f72b6..b83df2adc 100644 --- a/.env.sample +++ b/.env.sample @@ -3,7 +3,7 @@ APP_DEBUG=true APP_KEY=SomeRandomString APP_URL=http://localhost -DB_HOST=172.31.45.156 +DB_HOST=172.31.41.191 DB_DATABASE=homestead DB_USERNAME=homestead DB_PASSWORD=sePret^i From b607a1e46ad45fad0e4c58692bf6fefff72d1783 Mon Sep 17 00:00:00 2001 From: Nathaniel Amadi Date: Thu, 21 Apr 2022 16:16:19 +0100 Subject: [PATCH 04/12] Updated Jenkinsfile --- Jenkinsfile | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/Jenkinsfile b/Jenkinsfile index 8b1378917..31b27f69e 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1 +1,30 @@ +pipeline { + agent any + stages { + + stage("Initial cleanup") { + steps { + dir("${WORKSPACE}") { + deleteDir() + } + } + } + + stage('Checkout SCM') { + steps { + git branch: 'main', url: 'https://github.com/stwalez/php-todo.git' + } + } + + stage('Prepare Dependencies') { + steps { + sh 'mv .env.sample .env' + sh 'composer install' + sh 'php artisan migrate' + sh 'php artisan db:seed' + sh 'php artisan key:generate' + } + } + } + } From 9d0d72f334ac1aafda4309ad4df9b53a6f79acb9 Mon Sep 17 00:00:00 2001 From: amadinathaniel Date: Thu, 21 Apr 2022 17:21:38 +0100 Subject: [PATCH 05/12] Update Jenkinsfile --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 31b27f69e..c3143274b 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -13,7 +13,7 @@ pipeline { stage('Checkout SCM') { steps { - git branch: 'main', url: 'https://github.com/stwalez/php-todo.git' + git branch: 'main', url: 'https://github.com/amadinathaniel/php-todo.git' } } From 6a32f304caf8d985cfe9de277351322c83511c49 Mon Sep 17 00:00:00 2001 From: Nathaniel Amadi Date: Thu, 21 Apr 2022 22:09:16 +0100 Subject: [PATCH 06/12] Updated Jenkinsfile --- Jenkinsfile | 77 +++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 54 insertions(+), 23 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index c3143274b..555c07df9 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,30 +1,61 @@ pipeline { - agent any + agent any - stages { + stages { - stage("Initial cleanup") { - steps { - dir("${WORKSPACE}") { - deleteDir() - } + stage("Initial cleanup") { + steps { + dir("${WORKSPACE}") { + deleteDir() + } + } } - } - stage('Checkout SCM') { - steps { - git branch: 'main', url: 'https://github.com/amadinathaniel/php-todo.git' - } - } - - stage('Prepare Dependencies') { - steps { - sh 'mv .env.sample .env' - sh 'composer install' - sh 'php artisan migrate' - sh 'php artisan db:seed' - sh 'php artisan key:generate' + stage('Checkout SCM') { + steps { + git branch: 'main', url: 'https://github.com/amadinathaniel/php-todo.git' + } + } + + stage('Prepare Dependencies') { + steps { + sh 'mv .env.sample .env' + sh 'composer install' + sh 'php artisan migrate' + sh 'php artisan db:seed' + sh 'php artisan key:generate' + } + } + + stage('Execute Unit Tests') { + steps { + sh './vendor/bin/phpunit' + } + + } + + stage('Code Analysis') { + steps { + sh 'phploc app/ --log-csv build/logs/phploc.csv' + + } + } + + stage('Plot Code Coverage Report') { + steps { + + plot csvFileName: 'plot-396c4a6b-b573-41e5-85d8-73613b2ffffb.csv', csvSeries: [[displayTableFlag: false, exclusionValues: 'Lines of Code (LOC),Comment Lines of Code (CLOC),Non-Comment Lines of Code (NCLOC),Logical Lines of Code (LLOC) ', file: 'build/logs/phploc.csv', inclusionFlag: 'INCLUDE_BY_STRING', url: '']], group: 'phploc', numBuilds: '100', style: 'line', title: 'A - Lines of code', yaxis: 'Lines of Code' + plot csvFileName: 'plot-396c4a6b-b573-41e5-85d8-73613b2ffffb.csv', csvSeries: [[displayTableFlag: false, exclusionValues: 'Directories,Files,Namespaces', file: 'build/logs/phploc.csv', inclusionFlag: 'INCLUDE_BY_STRING', url: '']], group: 'phploc', numBuilds: '100', style: 'line', title: 'B - Structures Containers', yaxis: 'Count' + plot csvFileName: 'plot-396c4a6b-b573-41e5-85d8-73613b2ffffb.csv', csvSeries: [[displayTableFlag: false, exclusionValues: 'Average Class Length (LLOC),Average Method Length (LLOC),Average Function Length (LLOC)', file: 'build/logs/phploc.csv', inclusionFlag: 'INCLUDE_BY_STRING', url: '']], group: 'phploc', numBuilds: '100', style: 'line', title: 'C - Average Length', yaxis: 'Average Lines of Code' + plot csvFileName: 'plot-396c4a6b-b573-41e5-85d8-73613b2ffffb.csv', csvSeries: [[displayTableFlag: false, exclusionValues: 'Cyclomatic Complexity / Lines of Code,Cyclomatic Complexity / Number of Methods ', file: 'build/logs/phploc.csv', inclusionFlag: 'INCLUDE_BY_STRING', url: '']], group: 'phploc', numBuilds: '100', style: 'line', title: 'D - Relative Cyclomatic Complexity', yaxis: 'Cyclomatic Complexity by Structure' + plot csvFileName: 'plot-396c4a6b-b573-41e5-85d8-73613b2ffffb.csv', csvSeries: [[displayTableFlag: false, exclusionValues: 'Classes,Abstract Classes,Concrete Classes', file: 'build/logs/phploc.csv', inclusionFlag: 'INCLUDE_BY_STRING', url: '']], group: 'phploc', numBuilds: '100', style: 'line', title: 'E - Types of Classes', yaxis: 'Count' + plot csvFileName: 'plot-396c4a6b-b573-41e5-85d8-73613b2ffffb.csv', csvSeries: [[displayTableFlag: false, exclusionValues: 'Methods,Non-Static Methods,Static Methods,Public Methods,Non-Public Methods', file: 'build/logs/phploc.csv', inclusionFlag: 'INCLUDE_BY_STRING', url: '']], group: 'phploc', numBuilds: '100', style: 'line', title: 'F - Types of Methods', yaxis: 'Count' + plot csvFileName: 'plot-396c4a6b-b573-41e5-85d8-73613b2ffffb.csv', csvSeries: [[displayTableFlag: false, exclusionValues: 'Constants,Global Constants,Class Constants', file: 'build/logs/phploc.csv', inclusionFlag: 'INCLUDE_BY_STRING', url: '']], group: 'phploc', numBuilds: '100', style: 'line', title: 'G - Types of Constants', yaxis: 'Count' + plot csvFileName: 'plot-396c4a6b-b573-41e5-85d8-73613b2ffffb.csv', csvSeries: [[displayTableFlag: false, exclusionValues: 'Test Classes,Test Methods', file: 'build/logs/phploc.csv', inclusionFlag: 'INCLUDE_BY_STRING', url: '']], group: 'phploc', numBuilds: '100', style: 'line', title: 'I - Testing', yaxis: 'Count' + plot csvFileName: 'plot-396c4a6b-b573-41e5-85d8-73613b2ffffb.csv', csvSeries: [[displayTableFlag: false, exclusionValues: 'Logical Lines of Code (LLOC),Classes Length (LLOC),Functions Length (LLOC),LLOC outside functions or classes ', file: 'build/logs/phploc.csv', inclusionFlag: 'INCLUDE_BY_STRING', url: '']], group: 'phploc', numBuilds: '100', style: 'line', title: 'AB - Code Structure by Logical Lines of Code', yaxis: 'Logical Lines of Code' + plot csvFileName: 'plot-396c4a6b-b573-41e5-85d8-73613b2ffffb.csv', csvSeries: [[displayTableFlag: false, exclusionValues: 'Functions,Named Functions,Anonymous Functions', file: 'build/logs/phploc.csv', inclusionFlag: 'INCLUDE_BY_STRING', url: '']], group: 'phploc', numBuilds: '100', style: 'line', title: 'H - Types of Functions', yaxis: 'Count' + plot csvFileName: 'plot-396c4a6b-b573-41e5-85d8-73613b2ffffb.csv', csvSeries: [[displayTableFlag: false, exclusionValues: 'Interfaces,Traits,Classes,Methods,Functions,Constants', file: 'build/logs/phploc.csv', inclusionFlag: 'INCLUDE_BY_STRING', url: '']], group: 'phploc', numBuilds: '100', style: 'line', title: 'BB - Structure Objects', yaxis: 'Count' + } } - } } - } +} From 231da5b8c8831b22f9f4db4743e185f531c5f69e Mon Sep 17 00:00:00 2001 From: Nathaniel Amadi Date: Thu, 21 Apr 2022 22:45:32 +0100 Subject: [PATCH 07/12] Updated Jenkinsfile --- Jenkinsfile | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 555c07df9..0e7622412 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -57,5 +57,36 @@ pipeline { plot csvFileName: 'plot-396c4a6b-b573-41e5-85d8-73613b2ffffb.csv', csvSeries: [[displayTableFlag: false, exclusionValues: 'Interfaces,Traits,Classes,Methods,Functions,Constants', file: 'build/logs/phploc.csv', inclusionFlag: 'INCLUDE_BY_STRING', url: '']], group: 'phploc', numBuilds: '100', style: 'line', title: 'BB - Structure Objects', yaxis: 'Count' } } - } + + stage ('Package Artifact') { + steps { + sh 'zip -qr ${WORKSPACE}/php-todo.zip ${WORKSPACE}/*' + } + } + + stage ('Upload Artifact to Artifactory') { + steps { + script { + def server = Artifactory.server 'artifactory-server' + def uploadSpec = """{ + "files": [ + { + "pattern": "php-todo.zip", + "target": "PBL/php-todo", + "props": "type=zip;status=ready" + } + ] + }""" + server.upload spec: uploadSpec + } + } + } + + stage ('Deploy to Dev Environment') { + steps { + build job: 'ansible-config-mgt/main', parameters: [[$class: 'StringParameterValue', name: 'env', value: 'dev']], propagate: false, wait: true + } + } + + } } From dbb5304315d4048772a95872dd8ab2801e11a49f Mon Sep 17 00:00:00 2001 From: Nathaniel Amadi Date: Thu, 21 Apr 2022 23:12:41 +0100 Subject: [PATCH 08/12] Updated Jenkinsfile --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 0e7622412..09d9b9995 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -84,7 +84,7 @@ pipeline { stage ('Deploy to Dev Environment') { steps { - build job: 'ansible-config-mgt/main', parameters: [[$class: 'StringParameterValue', name: 'env', value: 'dev']], propagate: false, wait: true + build job: 'ansible-config-mgt/main', parameters: [[$class: 'StringParameterValue', name: 'env', value: 'dev.yml']], propagate: false, wait: true } } From 3256a18b266e36316905b06fedc1746e8afe3660 Mon Sep 17 00:00:00 2001 From: Nathaniel Amadi Date: Fri, 22 Apr 2022 15:32:14 +0100 Subject: [PATCH 09/12] Updated Jenkinsfile --- Jenkinsfile | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Jenkinsfile b/Jenkinsfile index 09d9b9995..65c55ce07 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -58,6 +58,18 @@ pipeline { } } + stage('SonarQube Quality Gate') { + environment { + scannerHome = tool 'sonarqubescanner' + } + steps { + withSonarQubeEnv('sonarqube') { + sh "${scannerHome}/bin/sonar-scanner" + } + + } + } + stage ('Package Artifact') { steps { sh 'zip -qr ${WORKSPACE}/php-todo.zip ${WORKSPACE}/*' From 28a171c3d83ec4b5ee594e3d1e6eef049231f7bc Mon Sep 17 00:00:00 2001 From: Nathaniel Amadi Date: Fri, 22 Apr 2022 15:59:48 +0100 Subject: [PATCH 10/12] Updated Jenkinsfile --- Jenkinsfile | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 65c55ce07..587dbccd1 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -59,15 +59,18 @@ pipeline { } stage('SonarQube Quality Gate') { - environment { - scannerHome = tool 'sonarqubescanner' - } - steps { - withSonarQubeEnv('sonarqube') { - sh "${scannerHome}/bin/sonar-scanner" + when { branch pattern: "^develop*|^hotfix*|^release*|^main*", comparator: "REGEXP"} + environment { + scannerHome = tool 'sonarqubescanner' + } + steps { + withSonarQubeEnv('sonarqube') { + sh "${scannerHome}/bin/sonar-scanner -Dproject.settings=sonar-project.properties" + } + timeout(time: 1, unit: 'MINUTES') { + waitForQualityGate abortPipeline: true + } } - - } } stage ('Package Artifact') { From 05ada443a96cd01635ffa26eed9546a9ef9a9cb3 Mon Sep 17 00:00:00 2001 From: amadinathaniel Date: Fri, 22 Apr 2022 23:22:15 +0100 Subject: [PATCH 11/12] Update Jenkinsfile --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 587dbccd1..ee00b52a9 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -79,7 +79,7 @@ pipeline { } } - stage ('Upload Artifact to Artifactory') { + stage ('Upload Artifact to Jfrog Artifactory') { steps { script { def server = Artifactory.server 'artifactory-server' From d1d9e1c04719677942daeda82c5fc3671c54d705 Mon Sep 17 00:00:00 2001 From: amadinathaniel Date: Fri, 22 Apr 2022 23:34:24 +0100 Subject: [PATCH 12/12] Update Jenkinsfile --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index ee00b52a9..587dbccd1 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -79,7 +79,7 @@ pipeline { } } - stage ('Upload Artifact to Jfrog Artifactory') { + stage ('Upload Artifact to Artifactory') { steps { script { def server = Artifactory.server 'artifactory-server'