首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何解决“请提供具有sonar.java.binaries属性的编译类”?

如何解决“请提供具有sonar.java.binaries属性的编译类”?
EN

Stack Overflow用户
提问于 2022-04-09 18:21:22
回答 1查看 333关注 0票数 0

我尝试了其他人发布的所有可能的解决方案,但我仍然在努力解决这个问题。我相信在我的案例中,它必须对agents做些什么。我将发布2个代码,其中一个代码工作,而另一个代码不工作。这两个代码调用相同的groovy方法,但仍然第二个代码片段不工作。

下面的code 1工作正常,并成功地执行了管道:

代码语言:javascript
复制
pipeline{
        agent { label 'docker-kitchensink-slave' }

        stages{
            stage('Checkout') {
                steps{
                    checkout scm
                }
            }

            //Build and Unit Tests
            stage('Build and Unit Tests') {
                steps{
                    script{
                        if (buildType.buildSystem == 'npm'){
                            buildNpm(configuration)
                        } else {
                            build(configuration)
                        }
                    }
                }
            }

            // SonarQube Analysis
            stage('SonarQube analysis') {
                steps{
                    script{
                        if (buildType.buildSystem != 'npm'){
                            sonarQubeGating(configuration)
                        }
                    }
                }
            }

            // Build Docker Image and Push to Artifactory
            stage('Build Docker Image and Push to Artifactory') {
                steps{
                    artifactoryImagePush(configuration)
                }
            }

            // Approve DEV Deployment
            stage('Approve Dev Deployment') {
                agent none
                when {
                    anyOf {
                        expression {
                            return (env.GIT_BRANCH.equals('master') || env.GIT_BRANCH.startsWith('hotfix-'))
                        }
                    }
                }
                steps{
                    approveDeployment()
                }
            }
        }
    }

下面的code 2不起作用:

代码语言:javascript
复制
pipeline{
        agent none

        stages{
            stage('Checkout') {
                agent { label 'docker-kitchensink-slave' }
                steps{
                    checkout scm
                }
            }

            //Build and Unit Tests
            stage('Build and Unit Tests') {
                agent { label 'docker-kitchensink-slave' }
                steps{
                    script{
                        if (buildType.buildSystem == 'npm'){
                            buildNpm(configuration)
                        } else {
                            build(configuration)
                        }
                    }
                }
            }

            // SonarQube Analysis
            stage('SonarQube analysis') {
                agent { label 'docker-kitchensink-slave' }
                steps{
                    script{
                        if (buildType.buildSystem != 'npm'){
                            sonarQubeGating(configuration)
                        }
                    }
                }
            }

            // Build Docker Image and Push to Artifactory
            stage('Build Docker Image and Push to Artifactory') {
                agent { label 'docker-kitchensink-slave' }
                steps{
                    unstash 'artifacts'
                    unstash 'artifacts'
                    artifactoryImagePush(configuration)
                }
            }

            // Approve DEV Deployment
            stage('Approve Dev Deployment') {
                agent none
                when {
                    anyOf {
                        expression {
                            return (env.GIT_BRANCH.equals('master') || env.GIT_BRANCH.startsWith('hotfix-'))
                        }
                    }
                }
                steps{
                    approveDeployment()
                }
            }
        }
    }

我得到的错误如下:

项目xyz-服务上的目标org.sonarsource.scanner.maven:sonar-maven-plugin:3.6.0.1398:sonar (默认-cli)执行失败:您的项目包含.java文件,请提供带有sonar.java.binaries属性的编译类,或者将它们排除在sonar.exclusions属性的分析之外。->帮助1

下面是我的sonar代码:

代码语言:javascript
复制
void call(Map optionParams = [:]) {
    script {
        try {
            String jacocoPath = optionParams.get('buildSystem').equals('gradle') ?
                    'build/JacocoReport/test/jacocoTestReport.xml' : 'target/site/jacoco/jacoco.xml'

            glSonarMavenScan gitUserCredentialsId: 'sonar-key', javaVersionForSonar: '11.0', mavenVersion: '3.5.4',
                    additionalProps: ['sonar.coverage.jacoco.xmlReportPaths' : jacocoPath]
        } catch (Exception e) {
            echo "The following Sonar exception thrown ${e}"
            //Stop build here, unless 'requireSonar' is set to False (String or Boolean)
            if (!optionParams.get('requireSonar').toString().equalsIgnoreCase('false')) {
                throw e
            }
        }
    }
}
EN

回答 1

Stack Overflow用户

发布于 2022-04-10 23:16:42

我有点搞不懂你想要达到什么目的。你展示的是起作用的代码。与第二个块相比,您是想了解第一个块为什么工作,还是只想让它正常工作?如果是后者,显然你已经做好了。

如果是前者,我只熟悉脚本化的管道,而不是声明性的管道,但在我看来,如果有多个满足该标签的构建节点,那么这些“代理”行中的每一行都可能会选择一个构建节点,而每个行可能会选择一个不同的节点。如果构建步骤执行与运行sonarqube扫描不同的节点,您将发现自己处于没有任何编译类的工作区中。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71810753

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档