简体   繁体   English

如何将 Angular 项目的 Jenkinsfile 与 Sonarqube 集成

[英]How to integrate an angular project's Jenkinsfile with Sonarqube

I have an angularjs project.我有一个 angularjs 项目。 the project has a Jenkinsfile(declarative pipeline) which can build the jenkinsjob when a push is done.该项目有一个 Jenkinsfile(声明性管道),它可以在推送完成时构建 jenkinsjob。 I'm trying to include a sonarqube action here for static scan.我正在尝试在此处包含用于静态扫描的声纳操作。 Searched a lot for angular projects with my scenario.在我的场景中搜索了很多角度项目。 but most of the examples i checked have pom.xml file(cause they were either java related projects).但是我检查的大多数示例都有 pom.xml 文件(因为它们要么是与 Java 相关的项目)。

I have written a sonar-projects.properties in root and added all necessary item:我在 root 中编写了一个sonar-projects.properties并添加了所有必要的项目:

sonar.projectKey=apols:webproject
sonar.projectName=webproject
sonar.projectVersion=1.0.0
sonar.projectDescription=Static analysis for the AppName
sonar.sources=www
sonar.exclusions=**/node_modules/**,**/*.spec.ts,**/dist/**,**/docs/**,**/*.js,**/coverage/**
sonar.tests=www 
sonar.test.inclusions=**/*.spec.ts
sonar.ts.tslint.configPath=tslint.json
sonar.javascript.lcov.reportPaths=coverage/lcov.info
sonar.ts.coverage.lcovReportPath=coverage/lcov.info

My Jenkinsfile's sonar scan portion -我的Jenkinsfile 的声纳扫描部分 -

stage('Sonarqube') {
     steps {
        container('maven') {
            script {
               withSonarQubeEnv('SonarQube') {
                  sh 'mvn clean package sonar:sonar'
               }
               timeout(time: 10, unit: 'MINUTES') {
                    waitForQualityGate abortPipeline: true
               }
            }
        }
     }
}

As you can see i'm using the maven container in jenkins.如您所见,我在 jenkins 中使用了 Maven 容器。

When the jenkins job runs, when it executes this line in Jenkinsfile - sh 'mvn clean package sonar:sonar' , it checks for the pom.xml file and fails.当 jenkins 作业运行时,当它在 Jenkinsfile 中执行这一行 - sh 'mvn clean package sonar:sonar' ,它会检查pom.xml文件并失败。 So how can i point this to my sonar-projects.properties .那么我怎么能把它指向我的sonar-projects.properties Please help请帮忙

You have to execute native SonarQube Scanner instead of SonarQube Scanner for Maven.您必须为 Maven 执行本机 SonarQube Scanner 而不是 SonarQube Scanner。

stage('Sonarqube') {
    steps {
        container('SonarQubeScanner') {
            withSonarQubeEnv('SonarQube') {
                sh "/usr/local/sonar-scanner"
            }
            timeout(time: 10, unit: 'MINUTES') {
                waitForQualityGate abortPipeline: true
            }
        }
    }
}

container('SonarQubeScanner') and sh "/usr/local/sonar-scanner" are just examples, but there are many docker containers with SonarQube Scanner, see Docker Hub . container('SonarQubeScanner')sh "/usr/local/sonar-scanner"只是示例,但是有许多带有 SonarQube Scanner 的 docker 容器,请参阅Docker Hub

Read more about Analyzing with SonarQube Scanner .阅读有关使用 SonarQube 扫描仪进行分析的更多信息。

How to do it without containers: How to execute SonarQube scanner in Jenkins Declarative Pipeline without Maven and Docker如何在没有容器的情况下做到这一点:如何在没有 Maven 和 Docker 的情况下在 Jenkins 声明式管道中执行 SonarQube 扫描仪

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM