From 6b53a3c5b023fbaca1e43172dcbbb26f625de66a Mon Sep 17 00:00:00 2001 From: Ademola Sobaki Date: Wed, 20 Sep 2023 09:19:18 +0100 Subject: [PATCH 01/18] add jenkinsfile --- Jenkinsfile | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 Jenkinsfile diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 000000000..2adfe223b --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,30 @@ +pipeline { + agent any + + stages { + + stage("Initial cleanup") { + steps { + dir("${WORKSPACE}") { + deleteDir() + } + } + } + + stage('Checkout SCM') { + steps { + git branch: 'main', url: 'https://github.com/demola07/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' + } + } + } +} \ No newline at end of file From 6089e13da163975f62d3b4f5cad551967bddff7a Mon Sep 17 00:00:00 2001 From: Ademola Sobaki Date: Wed, 20 Sep 2023 11:29:59 +0100 Subject: [PATCH 02/18] update env files --- .env.sample | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.env.sample b/.env.sample index 1c39502a5..3ad93fda2 100644 --- a/.env.sample +++ b/.env.sample @@ -3,10 +3,12 @@ APP_DEBUG=true APP_KEY=SomeRandomString APP_URL=http://localhost -DB_HOST=127.0.0.1 +DB_HOST=172.31.36.86 DB_DATABASE=homestead DB_USERNAME=homestead DB_PASSWORD=sePret^i +DB_CONNECTION=mysql +DB_PORT=3306 CACHE_DRIVER=file SESSION_DRIVER=file From 732c9eba801092f73641d9edec260228ca507806 Mon Sep 17 00:00:00 2001 From: Ademola Sobaki Date: Wed, 20 Sep 2023 11:42:14 +0100 Subject: [PATCH 03/18] update jenkinsfile --- Jenkinsfile | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Jenkinsfile b/Jenkinsfile index 2adfe223b..b881bd53f 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -26,5 +26,10 @@ pipeline { sh 'php artisan key:generate' } } + + stage('Execute Unit Tests') { + steps { + sh './vendor/bin/phpunit' + } } } \ No newline at end of file From 7ba200d30f9d39d61d9ba84cb4877f5693b05e37 Mon Sep 17 00:00:00 2001 From: Ademola Sobaki Date: Wed, 20 Sep 2023 11:44:33 +0100 Subject: [PATCH 04/18] update jenkinsfile --- Jenkinsfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Jenkinsfile b/Jenkinsfile index b881bd53f..4af5fb59c 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -32,4 +32,5 @@ pipeline { sh './vendor/bin/phpunit' } } +} } \ No newline at end of file From d410463ea1eb568788f76cd894a0182a899c96e0 Mon Sep 17 00:00:00 2001 From: Ademola Sobaki Date: Wed, 20 Sep 2023 11:54:07 +0100 Subject: [PATCH 05/18] update jenkinsfile --- Jenkinsfile | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/Jenkinsfile b/Jenkinsfile index 4af5fb59c..08c94cfec 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -32,5 +32,28 @@ pipeline { 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' + } + } } } \ No newline at end of file From b60bdcbd98067896242f0ae51ff4c3c618cf5675 Mon Sep 17 00:00:00 2001 From: Ademola Sobaki Date: Wed, 20 Sep 2023 12:17:23 +0100 Subject: [PATCH 06/18] update jenkinsfile to add artifactory stage --- Jenkinsfile | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/Jenkinsfile b/Jenkinsfile index 08c94cfec..329981250 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -55,5 +55,31 @@ 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 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": "dareyProject/php-todo", + "props": "type=zip;status=ready" + + } + ] + }""" + + server.upload spec: uploadSpec + } + } + } } } \ No newline at end of file From 9981150edce28c7559d1263d64026cc8600df7dc Mon Sep 17 00:00:00 2001 From: Ademola Sobaki Date: Wed, 20 Sep 2023 12:47:23 +0100 Subject: [PATCH 07/18] update jenkinsfile --- Jenkinsfile | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Jenkinsfile b/Jenkinsfile index 329981250..96935bbe2 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -81,5 +81,11 @@ pipeline { } } } + + stage ('Deploy to Dev Environment') { + steps { + build job: 'ansible-config-mgt/main', parameters: [[$class: 'StringParameterValue', name: 'env', value: 'dev']], propagate: false, wait: true + } + } } } \ No newline at end of file From 8f501bf522eaabe6ab89cab6e7d28b87ac10cf75 Mon Sep 17 00:00:00 2001 From: Ademola Sobaki Date: Wed, 20 Sep 2023 16:33:22 +0100 Subject: [PATCH 08/18] update jenkinsfile --- Jenkinsfile | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Jenkinsfile b/Jenkinsfile index 96935bbe2..c73f19339 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -56,6 +56,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 php-todo.zip ${WORKSPACE}/*' From 6c20623c0870120bc884017c3f50e6fb480148af Mon Sep 17 00:00:00 2001 From: Ademola Sobaki Date: Wed, 20 Sep 2023 16:37:03 +0100 Subject: [PATCH 09/18] update jenkinsfile --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index c73f19339..560160774 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -61,7 +61,7 @@ pipeline { scannerHome = tool 'SonarQubeScanner' } steps { - withSonarQubeEnv('sonarqube') { + withSonarQubeEnv('sonarqube-server') { sh "${scannerHome}/bin/sonar-scanner" } From 5cd6a08548f2e625dfa08ff9b676fbf2aa09ce71 Mon Sep 17 00:00:00 2001 From: Ademola Sobaki Date: Wed, 20 Sep 2023 17:02:27 +0100 Subject: [PATCH 10/18] update jenkinsfile --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 560160774..c73f19339 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -61,7 +61,7 @@ pipeline { scannerHome = tool 'SonarQubeScanner' } steps { - withSonarQubeEnv('sonarqube-server') { + withSonarQubeEnv('sonarqube') { sh "${scannerHome}/bin/sonar-scanner" } From 22398506f6544725c2c0cbaacd2df97f5b7632b1 Mon Sep 17 00:00:00 2001 From: Ademola Sobaki Date: Wed, 20 Sep 2023 17:27:00 +0100 Subject: [PATCH 11/18] update jenkinsfile --- Jenkinsfile | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index c73f19339..226bdd519 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -58,15 +58,14 @@ pipeline { stage('SonarQube Quality Gate') { environment { - scannerHome = tool 'SonarQubeScanner' + scannerHome = tool 'SonarQubeScanner' } - steps { - withSonarQubeEnv('sonarqube') { - sh "${scannerHome}/bin/sonar-scanner" - } - + steps { + withSonarQubeEnv('sonarqube') { + sh "${scannerHome}/bin/sonar-scanner" } } +} stage ('Package Artifact') { steps { From 386a491c2dbd45bbfbcdc30ea4db25d65be76f77 Mon Sep 17 00:00:00 2001 From: Ademola Sobaki Date: Thu, 21 Sep 2023 23:18:14 +0100 Subject: [PATCH 12/18] update jenkins file --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 226bdd519..cf6b387e1 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -65,7 +65,7 @@ pipeline { sh "${scannerHome}/bin/sonar-scanner" } } -} + } stage ('Package Artifact') { steps { From aea1c13f6c91c44d8e812fd7ffe7c9230729ff12 Mon Sep 17 00:00:00 2001 From: Ademola Sobaki Date: Fri, 22 Sep 2023 00:26:12 +0100 Subject: [PATCH 13/18] update jenkins file --- Jenkinsfile | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index cf6b387e1..a0b7ffe1f 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -60,10 +60,11 @@ pipeline { environment { scannerHome = tool 'SonarQubeScanner' } - steps { - withSonarQubeEnv('sonarqube') { - sh "${scannerHome}/bin/sonar-scanner" - } + withSonarQubeEnv('sonarqube') { + sh """ + export JAVA_TOOL_OPTIONS='--add-opens=java.base/java.lang=ALL-UNNAMED' + ${scannerHome}/bin/sonar-scanner + """ } } From 4c76ed59ac73b498d453b58d31bf5c718a3b1c8a Mon Sep 17 00:00:00 2001 From: Ademola Sobaki Date: Fri, 22 Sep 2023 00:27:26 +0100 Subject: [PATCH 14/18] update jenkins file --- Jenkinsfile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index a0b7ffe1f..812f91854 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -60,12 +60,14 @@ pipeline { environment { scannerHome = tool 'SonarQubeScanner' } - withSonarQubeEnv('sonarqube') { + steps { + withSonarQubeEnv('sonarqube') { sh """ export JAVA_TOOL_OPTIONS='--add-opens=java.base/java.lang=ALL-UNNAMED' ${scannerHome}/bin/sonar-scanner """ } + } } stage ('Package Artifact') { From 7f4563a1cabf4f9de0f0879e7cbeb6729f1f0186 Mon Sep 17 00:00:00 2001 From: Ademola Sobaki Date: Fri, 22 Sep 2023 00:43:17 +0100 Subject: [PATCH 15/18] update jenkins file --- Jenkinsfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 812f91854..41c3ac399 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -66,8 +66,8 @@ pipeline { export JAVA_TOOL_OPTIONS='--add-opens=java.base/java.lang=ALL-UNNAMED' ${scannerHome}/bin/sonar-scanner """ - } - } + } + } } stage ('Package Artifact') { From 172e5eaba5309202a75f1fb70db731a2d22fc030 Mon Sep 17 00:00:00 2001 From: Ademola Sobaki Date: Fri, 22 Sep 2023 22:53:30 +0100 Subject: [PATCH 16/18] update --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 41c3ac399..d600e2c99 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -56,7 +56,7 @@ pipeline { } } - stage('SonarQube Quality Gate') { + stage('SonarQube Quality Gate') { environment { scannerHome = tool 'SonarQubeScanner' } From de0b52223b7aefc67939f1d2cac6b3568946be74 Mon Sep 17 00:00:00 2001 From: Ademola Sobaki Date: Fri, 22 Sep 2023 23:01:09 +0100 Subject: [PATCH 17/18] sonar step with branch pattern match --- Jenkinsfile | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index d600e2c99..e433a99b2 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -56,18 +56,19 @@ pipeline { } } - stage('SonarQube Quality Gate') { - environment { - scannerHome = tool 'SonarQubeScanner' - } - steps { - withSonarQubeEnv('sonarqube') { - sh """ - export JAVA_TOOL_OPTIONS='--add-opens=java.base/java.lang=ALL-UNNAMED' - ${scannerHome}/bin/sonar-scanner - """ + stage('SonarQube Quality Gate') { + 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 d349ad004f7ee30643c5fef806810977aba1cea4 Mon Sep 17 00:00:00 2001 From: Ademola Sobaki Date: Fri, 22 Sep 2023 23:04:59 +0100 Subject: [PATCH 18/18] add both sonar steps --- Jenkinsfile | 38 ++++++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index e433a99b2..a7188123c 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -56,21 +56,35 @@ pipeline { } } - stage('SonarQube Quality Gate') { - 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('SonarQube Quality Gate') { + environment { + scannerHome = tool 'SonarQubeScanner' + } + steps { + withSonarQubeEnv('sonarqube') { + sh """ + export JAVA_TOOL_OPTIONS='--add-opens=java.base/java.lang=ALL-UNNAMED' + ${scannerHome}/bin/sonar-scanner + """ } + } } + // stage('SonarQube Quality Gate') { + // 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') { steps { sh 'zip -qr php-todo.zip ${WORKSPACE}/*'