Gitlab CI/CD 集成 SonarQube 扫描服务
[TOC]
环境:Docker
gitlab
gitlab-runner
sonarqube
postgresql
使用示例
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 stages: - sonar-scanner sonar: stage: sonar-scanner script: - sonar-scanner -Dsonar.projectKey=cd_demo -Dsonar.sources=. -Dsonar.host.url=http://10.18.27.80:9823 -Dsonar.login=a138bc0d36c7130bb30aebbaffbc44148b6ab8e4 tags: - sonar when: always
Sonar 服务
Sonar 集成 GitLab
admin 安装 git 插件 Administration
->marketpalce
-> search git
->restart server
ALM Intergrations
Gitlab Application
Token-Secret
Gitlab-runner 服务
构建 gitlab-runner
镜像,集成 node
,sonar-scanner
注册 Runner
:
gitlab-runner
register
输入 gitlab-host
输入 runner-token
输入 tag
选择执行方式 shell
开启 Runner
不匹配 tag
执行,在 CI/CD
-> runner
的设置里
Gitlab-runner 容器编排
docker-compose.yml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 runner: container_name: 'gitlab-runner' build: ../../server/gitlab-runner/ restart: always ports: - '8093:8093' web: image: 'gitlab/gitlab-ee:latest' restart: always hostname: 'gitlab.example.com' environment: GITLAB_OMNIBUS_CONFIG: | external_url 'http://gitlab.example.com:8929' gitlab_rails['gitlab_shell_ssh_port'] = 2224 ports: - '8929:8929' - '2224:22' volumes: - '$GITLAB_HOME/config:/etc/gitlab' - '$GITLAB_HOME/logs:/var/log/gitlab' - '$GITLAB_HOME/data:/var/opt/gitlab'
gitlab-runner/Dockerfile
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 FROM gitlab/gitlab-runner:latest LABEL MAINTAINER=[email protected] RUN export LANG=en_US.UTF-8 && export LANGUAGE=en_US RUN apt-get update && apt-get install -y nodejs vim unzip RUN cd /opt && \ wget https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-4.0.0.1744-linux.zip && \ unzip sonar-scanner-cli-4.0.0.1744-linux.zip && \ mv sonar-scanner-4.0.0.1744-linux sonar-scanner RUN ln -s /opt/sonar-scanner/bin/sonar-scanner /usr/bin/sonar-scanner && sonar-scanner -v
注意问题
系统语言需设置 LCALL LANGUAGE LANG=en_US.UTF-8
[submodule "golang/example"]
active = true
url = [email protected] :baqianxin/examples.git
[submodule "spider/chineseocr_lite"]
url = [email protected] :baqianxin/chineseocr_lite.git
active = true