How to integrate Sonar Quality Gates with Gitlab-CI

后端 未结 4 647
不思量自难忘°
不思量自难忘° 2020-12-15 14:27

I have a gitlab-ci integration that require a sonar analysis and if the quality gates pass, to build a docker image.

Is this possible using gitlab-ci ?

4条回答
  •  余生分开走
    2020-12-15 15:08

    You should try the Sonar Build Breaker plugin. It enables returning non-zero which would break the Gitlab CI Runner's build, not performing the next step (building the Docker image).

    Create a .gitlab-ci.yml file in the root of your project:

    stages:
      - sonarqube
      - docker_build
    image: maven:3-jdk-8
    sonarqube:
      stage: sonarqube
      script:
        - # sonarqube running command (plugin installed), mvn blabla
    docker_build
       stage: docker_build
       script:
         - docker build .
    

    A commit to Gitlab will run the sonarqube stage and continue with docker_build only if sonarqube passes the Quality Gate.

提交回复
热议问题