From 3c1afce417301bc9b68bf721a5b389a6481becb6 Mon Sep 17 00:00:00 2001 From: Isaac-Ayanda Date: Mon, 19 Sep 2022 12:40:58 +0000 Subject: [PATCH 01/11] added jenkinsfile --- jenkinsfile | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 jenkinsfile diff --git a/jenkinsfile b/jenkinsfile new file mode 100644 index 000000000..4ae0cdb44 --- /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/Isaac-Ayanda/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 0a760095d0c69548a008baf7bd2d547ca21ff0b6 Mon Sep 17 00:00:00 2001 From: Isaac-Ayanda Date: Mon, 19 Sep 2022 13:04:36 +0000 Subject: [PATCH 02/11] added Jenkinsfile --- jenkinsfile => Jenkinsfile | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename jenkinsfile => Jenkinsfile (100%) diff --git a/jenkinsfile b/Jenkinsfile similarity index 100% rename from jenkinsfile rename to Jenkinsfile From cd30f896e15ef2dbdd0650ed868c88273d2e9805 Mon Sep 17 00:00:00 2001 From: Isaac-Ayanda Date: Mon, 19 Sep 2022 13:49:06 +0000 Subject: [PATCH 03/11] updated db details --- .env.sample | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.env.sample b/.env.sample index 1c39502a5..9ab43b55a 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.23.220 DB_DATABASE=homestead DB_USERNAME=homestead DB_PASSWORD=sePret^i +DB_CONNECTION=mysql +DB_PORT=3306 CACHE_DRIVER=file SESSION_DRIVER=file From 340c5955b7c527021a23ff7d17b7daa4ce75f4d3 Mon Sep 17 00:00:00 2001 From: Isaac-Ayanda Date: Mon, 19 Sep 2022 14:06:31 +0000 Subject: [PATCH 04/11] updated Jenkinsfile --- Jenkinsfile | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Jenkinsfile b/Jenkinsfile index 4ae0cdb44..b1a19b791 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 8a000a6347b67ce3dbcd1cb0d23ee015c78db9a5 Mon Sep 17 00:00:00 2001 From: Isaac-Ayanda Date: Mon, 19 Sep 2022 14:09:16 +0000 Subject: [PATCH 05/11] updated Jenkinsfile --- Jenkinsfile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index b1a19b791..1b3e0af22 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -30,7 +30,7 @@ pipeline { stage('Execute Unit Tests') { steps { sh './vendor/bin/phpunit' - } - + } + } } -} \ No newline at end of file +|} \ No newline at end of file From 61fee3770535e7c3ef7b943e577e34dd1b0a6a63 Mon Sep 17 00:00:00 2001 From: Isaac-Ayanda Date: Mon, 19 Sep 2022 14:10:37 +0000 Subject: [PATCH 06/11] updated Jenkinsfile --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 1b3e0af22..4d403cbbf 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -33,4 +33,4 @@ pipeline { } } } -|} \ No newline at end of file +} \ No newline at end of file From e58e8a345c3711c4a55fdb1ee66c229465088afd Mon Sep 17 00:00:00 2001 From: Isaac-Ayanda Date: Mon, 19 Sep 2022 14:31:20 +0000 Subject: [PATCH 07/11] updated Jenkinsfile --- Jenkinsfile | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/Jenkinsfile b/Jenkinsfile index 4d403cbbf..61d997f56 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -32,5 +32,27 @@ 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 ef1b353243b0ec69de2094202b9c92737cd12fc8 Mon Sep 17 00:00:00 2001 From: Isaac-Ayanda Date: Mon, 19 Sep 2022 15:18:16 +0000 Subject: [PATCH 08/11] updated Jenkinsfile --- Jenkinsfile | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/Jenkinsfile b/Jenkinsfile index 61d997f56..13ec19da5 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -54,5 +54,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": "LBP/php-todo", + "props": "type=zip;status=ready" + + } + ] + }""" + + server.upload spec: uploadSpec + } + } + + } } } \ No newline at end of file From c23f5c1770f98c683abc6c76d78ebdf47ef511c3 Mon Sep 17 00:00:00 2001 From: Isaac-Ayanda Date: Tue, 20 Sep 2022 08:02:12 +0000 Subject: [PATCH 09/11] updated files --- Jenkinsfile | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Jenkinsfile b/Jenkinsfile index 13ec19da5..d40bbf9ec 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -80,5 +80,11 @@ pipeline { } } + stage ('Deploy to Dev Environment') { + steps { + build job: 'ansible-config-mgt2/main', parameters: [[$class: 'StringParameterValue', name: 'env', value: 'dev']], propagate: false, wait: true + } + } + } } \ No newline at end of file From 2e96d7a8cda7dccc9f1e37c82608b5f052214ca5 Mon Sep 17 00:00:00 2001 From: Isaac-Ayanda Date: Tue, 20 Sep 2022 14:42:32 +0000 Subject: [PATCH 10/11] updated Jenkinsfile --- Jenkinsfile | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Jenkinsfile b/Jenkinsfile index d40bbf9ec..432f9591e 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -54,6 +54,18 @@ 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('SonarQube Quality Gate') { + environment { + scannerHome = tool 'SonarQubeScanner' + } + steps { + withSonarQubeEnv('sonarqube') { + sh "${scannerHome}/bin/sonar-scanner" + } + + } + } stage ('Package Artifact') { steps { From 8a7ee4cd268988cff6ea0c0ffabdf4a8e99e8f6c Mon Sep 17 00:00:00 2001 From: Isaac-Ayanda Date: Tue, 20 Sep 2022 15:37:11 +0000 Subject: [PATCH 11/11] updated file --- Jenkinsfile | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 432f9591e..2b5d527a3 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -54,16 +54,19 @@ 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('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 } - } }