diff --git a/Jenkinsfile b/Jenkinsfile index a25609414ff442733402c7865d388566c37d923e..6ac04623dfee64bde7184fc6102987489aab714b 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -34,24 +34,16 @@ pipeline { else { sh 'npm run ci-build' } - - sh 'npm run ci-test' + withSonarQubeEnv('sonarqube'){ + sh 'npm run ci-sonar' + } } } } } post { always{ - junit testResults: 'goofy-client/junit.xml', skipPublishingChecks: true - - publishHTML (target: [ - allowMissing: false, - alwaysLinkToLastBuild: false, - keepAll: true, - reportDir: 'goofy-client/coverage/lcov-report', - reportFiles: 'index.html', - reportName: "Goofy-Client code coverage" - ]) + junit testResults: 'goofy-client/test-report.xml', skipPublishingChecks: true } } } @@ -62,11 +54,15 @@ pipeline { FAILED_STAGE=env.STAGE_NAME } container("maven-11"){ - configFileProvider([configFile(fileId: '9aac2fac-7d8d-4128-846b-0a61951df703', variable: 'MAVEN_SETTINGS')]) { - sh 'mvn --version' - - sh 'mvn -s $MAVEN_SETTINGS -pl -goofy-client clean install' - } + withSonarQubeEnv('sonarqube'){ + configFileProvider([configFile(fileId: '9aac2fac-7d8d-4128-846b-0a61951df703', variable: 'MAVEN_SETTINGS')]) { + sh 'mvn --version' + sh 'mvn -s $MAVEN_SETTINGS -pl -goofy-client clean install' + dir('goofy-server'){ + sh 'mvn sonar:sonar' + } + } + } } } post { @@ -74,7 +70,7 @@ pipeline { junit testResults: '**/target/surefire-reports/*.xml', skipPublishingChecks: true } } - } + } stage('Openshift build') { steps { diff --git a/goofy-client/.gitignore b/goofy-client/.gitignore index 3723dc1949a3e764ab7aa50b6300491dcd0bf809..732c9de86c02e85fa7969bb180aa144f3a153db1 100644 --- a/goofy-client/.gitignore +++ b/goofy-client/.gitignore @@ -7,6 +7,8 @@ junit.xml /apps/goofy-e2e/reports /apps/goofy-e2e/recordings +.scannerwork +test-report.xml # dependencies /node_modules diff --git a/goofy-client/package.json b/goofy-client/package.json index d7f7ae8c45030598d33de481b7f24d80a05a3695..b5a012a554ca5e0fadc713774a2d60658e874591 100644 --- a/goofy-client/package.json +++ b/goofy-client/package.json @@ -15,7 +15,8 @@ "test:debug:lib": "run-s \"ng -- test {1} --detectOpenHandles --watchAll\" --", "ci-build": "ng build --outputHashing=all", "ci-prodBuild": "ng build --prod --outputHashing=all", - "ci-test": "jest test a --ci --coverage --testResultsProcessor='jest-junit'", + "ci-test": "jest test a --ci --coverage --testResultsProcessor='jest-sonar-reporter'", + "ci-sonar": "npm run ci-test && sonar-scanner", "lint": "nx workspace-lint && ng lint", "affected:apps": "nx affected:apps", "affected:libs": "nx affected:libs", @@ -40,7 +41,8 @@ "cypress:delete-old-reports": "node apps/goofy-e2e/src/support/delete-old-reports.ts", "cypress:generate-report": "npm run cypress:merge-report ; npm run cypress:generate-html", "cypress:ci-run": "npm run cypress:delete-old-reports ; npm run cypress:run -- --config-file ./cypress-ci.json ; test=$(echo \"$?\") ; npm run cypress:generate-report ; exit $test", - "workspace-generator": "nx workspace-generator" + "workspace-generator": "nx workspace-generator", + "sonar-scanner": "jest test a --coverage --testResultsProcessor='jest-sonar-reporter' && sonar-scanner -Dsonar.host.url=https://sonarqube.ozg-sh.de/ -Dsonar.login=25dfb9ee83a79b0f4af445c63405651fcf391ee8" }, "private": true, "dependencies": { @@ -100,8 +102,10 @@ "jest-createspyobj": "^2.0.0", "jest-junit": "^12.0.0", "jest-marbles": "^2.5.1", - "jest-preset-angular": "8.3.2", - "prettier": "2.2.1", + "jest-preset-angular": "8.3.2", + "jest-sonar-reporter": "^2.0.0", + "prettier": "2.2.1", + "sonarqube-scanner": "^2.8.0", "ts-jest": "26.4.0", "ts-node": "9.1.1", "tslint": "6.1.3", diff --git a/goofy-client/sonar-project.properties b/goofy-client/sonar-project.properties new file mode 100644 index 0000000000000000000000000000000000000000..a1c7650d174c08c34c5f0f7816277b4d7418f2ca --- /dev/null +++ b/goofy-client/sonar-project.properties @@ -0,0 +1,7 @@ +sonar.projectKey=goofy-client +sonar.sources=apps/goofy/src,libs +sonar.tests=apps/goofy/src,libs +sonar.test.inclusions=**/*.spec.ts +sonar.typescript.lcov.reportPaths=coverage/lcov.info +sonar.testExecutionReportPaths=test-report.xml +sonar.sourceEncoding=UTF-8 \ No newline at end of file diff --git a/goofy-server/pom.xml b/goofy-server/pom.xml index 28ca4f1f471d0c5044f94e42ace3e733ebf2ab55..9677e1a959e50bac565358f3ceadef856d59e69e 100644 --- a/goofy-server/pom.xml +++ b/goofy-server/pom.xml @@ -173,13 +173,42 @@ </compilerArgs> </configuration> </plugin> + <plugin> + <groupId>org.jacoco</groupId> + <artifactId>jacoco-maven-plugin</artifactId> + <version>0.8.6</version> + <executions> + <execution> + <id>start-agent</id> + <goals> + <goal>prepare-agent</goal> + </goals> + <configuration> + <propertyName>surefire.jacoco.args</propertyName> + </configuration> + </execution> + <execution> + <id>generate-report</id> + <phase>package</phase> + <goals> + <goal>report</goal> + </goals> + </execution> + </executions> + </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-failsafe-plugin</artifactId> + <configuration> + <argLine>${surefire.jacoco.args}</argLine> + </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> + <configuration> + <argLine>${surefire.jacoco.args}</argLine> + </configuration> </plugin> <plugin> <groupId>org.springframework.boot</groupId> diff --git a/goofy-server/sonar-project.properties b/goofy-server/sonar-project.properties new file mode 100644 index 0000000000000000000000000000000000000000..10d23d8d9f30c9557e9556b91bda10dbe9c61dd5 --- /dev/null +++ b/goofy-server/sonar-project.properties @@ -0,0 +1,2 @@ +sonar.java.coveragePlugin=jacoco +sonar.jacoco.reportPath=target/jacoco.exec \ No newline at end of file diff --git a/pom.xml b/pom.xml index 9a626cc9d0076ccc4e26c7a635e1a3d82d2ff00b..7dda33584febe653d1f8ef272df6728bfff61bbb 100644 --- a/pom.xml +++ b/pom.xml @@ -34,6 +34,7 @@ <maven.surefire.version>3.0.0-M5</maven.surefire.version> <maven.failsafe.version>3.0.0-M5</maven.failsafe.version> <git-comit-id.plugin.version>4.0.3</git-comit-id.plugin.version> + <sonarqube.version>3.8.0.2131</sonarqube.version> </properties> <dependencyManagement> @@ -142,6 +143,12 @@ </configuration> </plugin> + <plugin> + <groupId>org.sonarsource.scanner.maven</groupId> + <artifactId>sonar-maven-plugin</artifactId> + <version>${sonarqube.version}</version> + </plugin> + <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-failsafe-plugin</artifactId>