From d91e33e404459df89f2a9bfac0742a680913a46f Mon Sep 17 00:00:00 2001 From: Obi Okoye Date: Tue, 21 Sep 2021 22:54:05 +0000 Subject: [PATCH 01/21] 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..79d207a15 --- /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/darey-devops/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 18ab3badf178e6421fc729ed27c7b243b8bb3963 Mon Sep 17 00:00:00 2001 From: Obi Okoye Date: Tue, 21 Sep 2021 22:55:53 +0000 Subject: [PATCH 02/21] add jenkinsfile --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 79d207a15..abfa113c3 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -13,7 +13,7 @@ pipeline { stage('Checkout SCM') { steps { - git branch: 'main', url: 'https://github.com/darey-devops/php-todo.git' + git branch: 'main', url: 'https://github.com/obinnao/php-todo.git' } } From 6f1389f4b661ba06f1c1eb39f6d9b47f4eb7a0ce Mon Sep 17 00:00:00 2001 From: Obi Okoye Date: Tue, 21 Sep 2021 23:17:33 +0000 Subject: [PATCH 03/21] add jenkinsfile --- .env.sample | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.env.sample b/.env.sample index 1c39502a5..c2eaf82bf 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.26.14 DB_DATABASE=homestead DB_USERNAME=homestead DB_PASSWORD=sePret^i +DB_CONNECTION=mysql +DB_PORT=3306 CACHE_DRIVER=file SESSION_DRIVER=file From 5e3f091c5494ee10487aa5b64c835e49cfc1e965 Mon Sep 17 00:00:00 2001 From: Obi Okoye Date: Tue, 21 Sep 2021 23:22:22 +0000 Subject: [PATCH 04/21] add jenkinsfile --- Jenkinsfile | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Jenkinsfile b/Jenkinsfile index abfa113c3..a1f5c66b4 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -26,5 +26,11 @@ pipeline { sh 'php artisan key:generate' } } + + stage('Execute Unit Tests') { + steps { + sh './vendor/bin/phpunit' + } } +} } \ No newline at end of file From e795c7011bfb69b00469a69d20254a6187261138 Mon Sep 17 00:00:00 2001 From: Obi Okoye Date: Tue, 21 Sep 2021 23:31:04 +0000 Subject: [PATCH 05/21] add jenkinsfile --- Jenkinsfile | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/Jenkinsfile b/Jenkinsfile index a1f5c66b4..5740270d5 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -32,5 +32,29 @@ 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 5e35461856f493643b5c7aaa47aa70c388e6aa34 Mon Sep 17 00:00:00 2001 From: Obi Okoye Date: Wed, 22 Sep 2021 00:27:19 +0000 Subject: [PATCH 06/21] add jenkinsfile --- Jenkinsfile | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/Jenkinsfile b/Jenkinsfile index 5740270d5..37d203da3 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -56,5 +56,31 @@ stage('Plot Code Coverage Report') { } } + 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": "PBL/php-todo", + "props": "type=zip;status=ready" + + } + ] + }""" + + server.upload spec: uploadSpec + } + } + + } } } \ No newline at end of file From 2a5dc957697eb4a401508298e64d597005c4e661 Mon Sep 17 00:00:00 2001 From: Obi Okoye Date: Wed, 22 Sep 2021 01:25:42 +0000 Subject: [PATCH 07/21] add jenkinsfile --- Jenkinsfile | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Jenkinsfile b/Jenkinsfile index 37d203da3..20a802200 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -82,5 +82,11 @@ stage('Plot Code Coverage Report') { } } + + stage ('Deploy to Dev Environment') { + steps { + build job: 'ansible-config/main', parameters: [[$class: 'StringParameterValue', name: 'env', value: 'dev']], propagate: false, wait: true + } + } } } \ No newline at end of file From b6a8b09da25de53c1d12849bd234d8d74973bdba Mon Sep 17 00:00:00 2001 From: Obi Okoye Date: Thu, 23 Sep 2021 00:15:39 +0000 Subject: [PATCH 08/21] add sonarqube --- Jenkinsfile | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 20a802200..459ebcc1b 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -56,6 +56,18 @@ stage('Plot Code Coverage Report') { } } + + 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}/*' @@ -87,6 +99,6 @@ stage('Plot Code Coverage Report') { steps { build job: 'ansible-config/main', parameters: [[$class: 'StringParameterValue', name: 'env', value: 'dev']], propagate: false, wait: true } - } + } } } \ No newline at end of file From e4c737ee032d12c8c5ed3fd01de1a9a889c62ce7 Mon Sep 17 00:00:00 2001 From: Obi Okoye Date: Thu, 23 Sep 2021 10:46:14 +0000 Subject: [PATCH 09/21] deploy --- Jenkinsfile | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 459ebcc1b..0c9282a12 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -56,18 +56,6 @@ stage('Plot Code Coverage Report') { } } - - 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 196d8c6958e226ee07cb04d25f419d43f4187636 Mon Sep 17 00:00:00 2001 From: Obi Okoye Date: Thu, 23 Sep 2021 11:02:46 +0000 Subject: [PATCH 10/21] deploy --- sonar.properties | 7 ------- 1 file changed, 7 deletions(-) delete mode 100644 sonar.properties diff --git a/sonar.properties b/sonar.properties deleted file mode 100644 index 38159e49d..000000000 --- a/sonar.properties +++ /dev/null @@ -1,7 +0,0 @@ -sonar.host.url=http://18.192.57.119:9000 -sonar.projectKey=php-todo -#----- Default source code encoding -sonar.sourceEncoding=UTF-8 -sonar.php.exclusions=**/vendor/** -sonar.php.coverage.reportPaths=build/logs/phploc.csv -sonar.php.tests.reportPath=reports/unitreport.xml \ No newline at end of file From db577f5ef828f7d8b5a4379af3edf0a781bb1d06 Mon Sep 17 00:00:00 2001 From: Obi Okoye Date: Thu, 23 Sep 2021 20:45:31 +0000 Subject: [PATCH 11/21] add sonar --- Jenkinsfile | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Jenkinsfile b/Jenkinsfile index 0c9282a12..75f5aa460 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -56,6 +56,19 @@ stage('Plot Code Coverage Report') { } } + + 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 bcc147c195ad0d7379f74ab55f83ab5d48f82192 Mon Sep 17 00:00:00 2001 From: Obi Okoye Date: Thu, 23 Sep 2021 22:37:33 +0000 Subject: [PATCH 12/21] deploy --- Jenkinsfile | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 75f5aa460..c1b4880df 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -58,16 +58,19 @@ stage('Plot Code Coverage Report') { } 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" - } - - } - } + } + 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 { From 51308c5ad3326841d63648d9c4b30920b90ae977 Mon Sep 17 00:00:00 2001 From: Obi Okoye Date: Thu, 23 Sep 2021 23:57:59 +0000 Subject: [PATCH 13/21] deploy --- Jenkinsfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Jenkinsfile b/Jenkinsfile index c1b4880df..91ec87a99 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -105,4 +105,5 @@ stage('Plot Code Coverage Report') { } } } +} } \ No newline at end of file From 606b51fa903ca12123a2f5171f544e23ec3b925d Mon Sep 17 00:00:00 2001 From: Obi Okoye Date: Thu, 23 Sep 2021 23:58:43 +0000 Subject: [PATCH 14/21] deploy --- Jenkinsfile | 1 - 1 file changed, 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 91ec87a99..3a01c0971 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -106,4 +106,3 @@ stage('Plot Code Coverage Report') { } } } -} \ No newline at end of file From 79579b92f670b63cf83a6c77e09df46ffae9e817 Mon Sep 17 00:00:00 2001 From: Obi Okoye Date: Fri, 24 Sep 2021 17:41:22 +0000 Subject: [PATCH 15/21] add jenkinsfile --- Jenkinsfile | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 3a01c0971..822fe0ee6 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -57,18 +57,15 @@ stage('Plot Code Coverage Report') { } } - stage('SonarQube Quality Gate') { - when { branch pattern: "^develop*|^hotfix*|^release*|^main*", comparator: "REGEXP"} + stage('SonarQube Quality Gate') { 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 + sh "${scannerHome}/bin/sonar-scanner" } + } } From ac7ae0d0fde666120f6fa4f4cd66ce91df6f4168 Mon Sep 17 00:00:00 2001 From: Obi Okoye Date: Fri, 24 Sep 2021 19:12:47 +0000 Subject: [PATCH 16/21] deploy --- Jenkinsfile | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 822fe0ee6..3a01c0971 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -57,15 +57,18 @@ stage('Plot Code Coverage Report') { } } - stage('SonarQube Quality Gate') { + 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" + sh "${scannerHome}/bin/sonar-scanner -Dproject.settings=sonar-project.properties" + } + timeout(time: 1, unit: 'MINUTES') { + waitForQualityGate abortPipeline: true } - } } From 20dab2a1a6c53f27ec71f9b107cc40a8441e87b1 Mon Sep 17 00:00:00 2001 From: Obi Okoye Date: Fri, 24 Sep 2021 21:28:23 +0000 Subject: [PATCH 17/21] deploy --- Jenkinsfile | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 3a01c0971..f508782fd 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -58,20 +58,17 @@ stage('Plot Code Coverage Report') { } 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 - } - } - } - + environment { + scannerHome = tool 'SonarQubeScanner' + } + steps { + withSonarQubeEnv('sonarqube') { + sh "${scannerHome}/bin/sonar-scanner" + } + + } + } + stage ('Package Artifact') { steps { sh 'zip -qr php-todo.zip ${WORKSPACE}/*' From d5def4e0201e4b9e3a5832a106b2b2e47ee24055 Mon Sep 17 00:00:00 2001 From: Obi Okoye Date: Fri, 24 Sep 2021 23:09:12 +0000 Subject: [PATCH 18/21] deploy --- Jenkinsfile | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index f508782fd..59ee3521c 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -58,16 +58,19 @@ stage('Plot Code Coverage Report') { } 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') { steps { From c5496b47b672eebe8870283bf071c766154f2940 Mon Sep 17 00:00:00 2001 From: Obi Okoye Date: Sat, 25 Sep 2021 17:16:45 +0000 Subject: [PATCH 19/21] deploy --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 59ee3521c..7a31304f1 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -72,7 +72,7 @@ stage('Plot Code Coverage Report') { } } - stage ('Package Artifact') { + stage ('Package Artifact') steps { sh 'zip -qr php-todo.zip ${WORKSPACE}/*' } From c325fef17f5a7f98c9a69fd504eaa6c0f3360e46 Mon Sep 17 00:00:00 2001 From: Obi Okoye Date: Sat, 25 Sep 2021 17:20:25 +0000 Subject: [PATCH 20/21] deploy --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 7a31304f1..59ee3521c 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -72,7 +72,7 @@ stage('Plot Code Coverage Report') { } } - stage ('Package Artifact') + stage ('Package Artifact') { steps { sh 'zip -qr php-todo.zip ${WORKSPACE}/*' } From 529ed12866de685c5319f243ba7b68f4723cc1ca Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Wed, 8 Dec 2021 12:38:23 +0000 Subject: [PATCH 21/21] ammend code --- Jenkinsfile | 113 ++++++++++------------------------------------------ 1 file changed, 20 insertions(+), 93 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 59ee3521c..be086ee4a 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,108 +1,35 @@ pipeline { - agent any + agent any stages { - stage("Initial cleanup") { + stage("Initial cleanup") { steps { - dir("${WORKSPACE}") { + dir("${WORKSPACE}") { deleteDir() - } + } } - } - - stage('Checkout SCM') { - steps { - git branch: 'main', url: 'https://github.com/obinnao/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' + stage('Checkout SCM') { + steps { + git branch: 'main', url: 'https://github.com/Anefu/php-todo.git' + } } - } - - 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}/*' - } - - } - stage ('Upload Artifact to Artifactory') { + + stage('Build image') { 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 + sh "docker build -t anefu/php-todo:${env.BRANCH_NAME}-${env.BUILD_NUMBER} ." + } + } + stage('Docker Push') { + when { expression { response.status == 200 } } + steps { + withCredentials([usernamePassword(credentialsId: 'dockerHub', passwordVariable: 'dockerHubPassword', usernameVariable: 'dockerHubUser')]) { + sh "docker login -u ${env.dockerHubUser} -p ${env.dockerHubPassword}" + sh "docker push anefu/php-todo:${env.BRANCH_NAME}-${env.BUILD_NUMBER}" } - } - + } } - - stage ('Deploy to Dev Environment') { - steps { - build job: 'ansible-config/main', parameters: [[$class: 'StringParameterValue', name: 'env', value: 'dev']], propagate: false, wait: true } - } -} }