gitlab - 为什么 gitlab-ci.yml 不识别 sonarqube -Dsonar 命令?

标签 gitlab sonarqube build.gradle gitlab-ci

所以我正在尝试将 SonarQube 与我的 Gitlab CI 集成。现在这是我目前拥有的 gitlab-ci.yml 文件:

stages:
  - build
  - sonarqube-check
  - test
  - deploy



cache:
  paths:
    - .gradle/wrapper
    - .gradle/caches

build:
  stage: build
  script:
    - ./gradlew assemble
  artifacts:
    paths:
      - build/libs/*.jar
    expire_in: 1 week
  only:
    - master

sonarqube-check:
  stage: test
  image: gradle:jre11-slim
  variables:
    SONAR_USER_HOME: "${CI_PROJECT_DIR}/.sonar"  # Defines the location of the analysis task cache
    GIT_DEPTH: "0"  # Tells git to fetch all the branches of the project, required by the analysis task
  cache:
    key: "${CI_JOB_NAME}"
    paths:
      - .sonar/cache
  script: ./gradlew sonarqube -Dsonar.qualitygate.wait=true
  allow_failure: true
  only:
    - master


test:
  stage: test
  script:
    - ./gradlew check

deploy-prod:
  stage: deploy
  script:
    - echo "This job deploys something from the $CI_COMMIT_BRANCH branch."

after_script:
  - echo "End CI"

我的build.gradle

plugins {
    id 'org.springframework.boot' version '2.4.2'
    id 'io.spring.dependency-management' version '1.0.11.RELEASE'
    id 'java'
    id "org.sonarqube" version "2.7.1"
    id 'jacoco'
}

group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '15'

configurations {
    compileOnly {
        extendsFrom annotationProcessor
    }
}

repositories {
    mavenCentral()
}


dependencies {
    implementation 'org.apache.httpcomponents:httpcore:4.4.1'
    implementation 'org.apache.httpcomponents:httpclient:4.5'
    implementation('io.jsonwebtoken:jjwt:0.2')
    implementation 'org.springframework.boot:spring-boot-starter-mail'
    implementation 'org.springframework.boot:spring-boot-starter-security'
    implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
    implementation 'org.springframework.boot:spring-boot-starter-web'
    compile 'junit:junit:4.12'
    implementation 'org.modelmapper:modelmapper:2.4.1'
    compileOnly 'org.projectlombok:lombok'
    runtimeOnly 'mysql:mysql-connector-java'
    annotationProcessor 'org.projectlombok:lombok'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
    implementation 'org.eclipse.jgit:org.eclipse.jgit:5.4.2.201908231537-r'
    /**
     * JUnit jupiter with mockito.
     */
    testCompile group: 'org.springframework.security', name: 'spring-security-test', version: '5.1.6.RELEASE'
}
jacocoTestReport{
    dependsOn test
    reports{
        xml.enabled true
        csv.enabled false
        html.enabled false
        html.destination layout.buildDirectory.dir('jacocoHtml').get().asFile
    }
}

sonarqube{
    properties{
        property 'sonar.java.source', '1.8'
        property 'sonar.java.coveragePlugin', 'jacoco'
    }
}



test {
    useJUnitPlatform()
    finalizedBy jacocoTestReport
}

tasks["sonarqube"].dependsOn("jacocoTestReport")

问题是我一直收到这个错误:

Task '.qualitygate.wait=true' not found in root project 'demo'.

当我尝试使用 Dsonar.login 时,我也遇到了这个错误。 为什么会出现此错误,我该如何解决? 我是否需要向我的 build.gradle 文件中添加一些内容才能解决此问题?

最佳答案

这是因为您没有指定要运行的 gradle 任务:

./gradlew -Dsonar.qualitygate.wait=true

试试这个:

./gradlew sonarqube -Dsonar.qualitygate.wait=true

关于gitlab - 为什么 gitlab-ci.yml 不识别 sonarqube -Dsonar 命令?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67769872/

相关文章:

android - Android Studio 中的编译错误

gitlab - 我应该使用专用用户进行 GitLab 集成吗?

Gitlab runner 为每项工作拉取镜像

java - Ant Sonar 将多个报告合并为一个

java - jsp 中的非法属性(违反 Sonar )

android - 使用Gradle解决依赖版本控制

deployment - 将 gitlab 中的 puppeteer 与 gitlab-ci.yml 集成

mysql - 亚搏体育appGitLab CI : My Test Job doesn't pickup the mysql container

maven - 为什么我的 Sonar 扫描仪不运行创建一个 report-task.txt 文件?

Flutter 无法编译 apk : Finished with error: Gradle task assembleDebug failed with exit code 1