我是靠谱客的博主 爱撒娇自行车,最近开发中收集的这篇文章主要介绍自动化代码质量检测平台 sonarqube gitlab-ci runner搭建docker 部署 sonarqubedocker 安装 gitlab-ci runner手动注册 gitlab-runner register 进行配置或者手动修改config.toml 进行配置centos7 安装 gitlab-ci runner,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

目录

  • docker 部署 sonarqube
  • docker 安装 gitlab-ci runner
  • 手动注册 gitlab-runner register 进行配置
  • 或者手动修改config.toml 进行配置
  • centos7 安装 gitlab-ci runner

docker 部署 sonarqube

docker 部署 postgressql

docker pull postgres
docker run --privileged --name pgdb -e POSTGRES_USER=sonar -e POSTGRES_PASSWORD=sonar -p 5432:5432 -v /data0/postgresql/data:/var/lib/postgresql/data -d postgres

docker 部署 sonarqube:8.3.1-community


修改系统参数
sysctl -w vm.max_map_count=262144
docker pull sonarqube:8.3.1-community
docker run -d --name sonartest -p 9000:9000 sonarqube:8.3.1-community
将容器内配置文件复制到宿主机:
docker cp sonartest:/opt/sonarqube/conf /data0/sonarqube
docker cp sonartest:/opt/sonarqube/data /data0/sonarqube
docker cp sonartest:/opt/sonarqube/logs /data0/sonarqube
docker cp sonartest:/opt/sonarqube/extensions /data0/sonarqube
然后删除此容器
docker rm -f sonartest
修改文件夹权限
sudo chmod -R 777 /data0/sonarqube/
修改sonar.properties配置 或者docker run时直接指定 postgresql url、账号、密码
找到 /data0/sonarqube/conf/ 路径下的文件 sonar.properties,修改如下并保存.
vim /data0/sonarqube/conf/sonar.properties
# 找到如下配置去掉注释。并赋值 username,password
sonar.jdbc.username=sonar
sonar.jdbc.password=sonar
# 去掉 sonar.jdbc.url 注释,配置url
#----- PostgreSQL 9.3 or greater
# By default the schema named "public" is used. It can be overridden with the parameter "currentSchema".
sonar.jdbc.url=jdbc:postgresql://pgdb:5432/sonar
docker run --privileged --name sonarqube --link pgdb 
-e SONARQUBE_JDBC_USERNAME=sonar 
-e SONARQUBE_JDBC_PASSWORD=sonar 
-e SONARQUBE_JDBC_URL=jdbc:postgresql://pgdb:5432/sonar 
-p 9000:9000 
-v /etc/localtime:/etc/localtime 
-v /data0/sonarqube/conf:/opt/sonarqube/conf 
-v /data0/sonarqube/data:/opt/sonarqube/data

-v /data0/sonarqube/extensions:/opt/sonarqube/extensions 
-v /data0/sonarqube/logs:/opt/sonarqube/logs 
-d sonarqube:8.3.1-community

下载汉化插件
将下载的jar包移动到 /data0/sonarqube/extensions/plugins

下载 alibaba p3c插件
docker之SonarQube集成阿里p3c规则

重启sonarqube:docker restart sonarqube镜像id

docker 安装 gitlab-ci runner

docker pull gitlab/gitlab-runner:latest
docker run -d --name gitlab-runner --restart always 
-v /data0/gitlab-runner/config:/etc/gitlab-runner 
-v /data0/gitlab-runner/script:/home/gitlab-runner 
-v /data0/maven/repo:/root/.m2 
-v /var/run/docker.sock:/var/run/docker.sock 
gitlab/gitlab-runner:latest

项目中 根目录新建 .gitlab-ci.yml

variables:
MAVEN_CLI_OPTS: "-s .m2/settings.xml --batch-mode"
MAVEN_OPTS: "-Dmaven.repo.local=.m2/repository"
cache:
paths:
- .m2/repository/
- target/
stages:
- sonar
sonar_analyze:
stage: sonar
image:
name: maven:3.5.4
script:
- echo $CI_PROJECT_NAME
- sh /root/script/sonar_analyze.sh bop-fms-account-job
allow_failure: true
only:
- master
tags:
- checksonar

cd /usr/home/gitlab-runner/
vi sonar_analyze.sh

#!/bin/bash
SONAR_HOST_URL=http://10.13.177.27:9000
SONAR_TOKEN=1a040abebb0c4e616b83989588ebcd2689eac0d8
echo "当前项目:$1"
mvn clean verify sonar:sonar -Dsonar.projectKey=$1 -Dsonar.host.url=$SONAR_HOST_URL -Dsonar.login=$SONAR_TOKEN -Dmaven.test.skip=true
if [ $? -eq 0 ]; then
echo "sonarqube code-analyze over."
fi

手动注册 gitlab-runner register 进行配置

打开 gitlab --> settings --> CI/CD --> Runners 如下所示:
Set up a specific runner manually
Install GitLab Runner and ensure it’s running.
Register the runner with this URL:
https://git.intra.wb.com/

And this registration token:
KUzJKzWqyz4cCoKsA5JR

此处的 url 和 token 要和下面配置的 URL、 token一致

docker exec -it gitlab-runner gitlab-ci-multi-runner register
Please enter the gitlab-ci coordinator URL:
# 示例:http://gitlab.alibaba-inc.com/ci
Please enter the gitlab-ci token for this runner:
# xxxxxx
Please enter the gitlab-ci description for this runner:
# 示例:bop-fms-api
(推荐项目名称)
Please enter the gitlab-ci tags for this runner (comma separated):
# 示例:checksonar
Please enter the executor: docker, parallels, shell, kubernetes, docker-ssh, ssh, virtualbox, docker+machine, docker-ssh+machine:
# docker/ shell
(linux方式安装则用shell
docker方式安装则用 docker)
Please enter the default Docker image (e.g. ruby:2.1):
# maven:3.5.4
(docker 方式安装时使用)

或者手动修改config.toml 进行配置

docker cp gitlab-runner:/etc/gitlab-runner/ /data0/gitlab-runner/config
cd /data0/gitlab-runner/config
编辑 config.toml
concurrent = 1
check_interval = 0
[[runners]]
name = "ff9dfb843211"
url = "https://git.intra.wb.com/"
token = "KUzJKzWqyz4cCoKsA5JR"
executor = "docker"
[runners.custom_build_dir]
[runners.cache]
[runners.cache.s3]
[runners.cache.gcs]
[runners.cache.azure]
[runners.docker]
tls_verify = false
image = "maven:3-jdk-8"
privileged = false
disable_entrypoint_overwrite = false
oom_kill_disable = false
disable_cache = false
volumes = ["/cache","/data0/maven/repo:/root/.m2","/data0/gitlab-runner/script:/root/script"]
pull_policy = "if-not-present"
shm_size = 0

SonarQube + Gitlab-CI 实现自动化代码质量检测

centos7 安装 gitlab-ci runner

# 安装镜像
curl -L https://packages.gitlab.com/install/repositories/runner/gitlab-runner/script.rpm.sh | sudo bash
# 安装 runner
yum -y install gitlab-runner
# 查看版本信息
gitlab-runner -v
# 将 gitlab-runner 授予 root 权限
ps -ef | grep runner
gitlab-runner stop
gitlab-runner uninstall
gitlab-runner install --user=root --working-directory=/data0/gitlab-runner
gitlab-runner start
ps -ef | grep runner
输出:说明成功
root
8519
1
2 10:59 ?
00:00:00 /usr/bin/gitlab-runner run --working-directory /data0/gitlab-runner --config /etc/gitlab-runner/config.toml --service gitlab-runner --user root
root
8531
3121
0 10:59 pts/0
00:00:00 grep --color=auto runner

项目中 根目录新建 .gitlab-ci.yml

variables:
MAVEN_CLI_OPTS: "-s .m2/settings.xml --batch-mode"
MAVEN_OPTS: "-Dmaven.repo.local=.m2/repository"
cache:
paths:
#- .m2/repository/
#- target/
stages:
- sonar
sonar_analyze:
stage: sonar
script:
- echo $HOME
- sh /usr/home/gitlab-runner/sonar_analyze.sh bop-fms-query-info
allow_failure: true
only:
- query_merge_uat
tags:
- checksonar

cd /usr/home/gitlab-runner/
vi sonar_analyze.sh

#!/bin/bash
SONAR_HOST_URL=http://10.13.177.27:9000
SONAR_TOKEN=1a040abebb0c4e616b83989588ebcd2689eac0d8
echo "当前项目:$1"
mvn clean verify sonar:sonar -Dsonar.projectKey=$1 -Dsonar.host.url=$SONAR_HOST_URL -Dsonar.login=$SONAR_TOKEN -Dmaven.test.skip=true
if [ $? -eq 0 ]; then
echo "sonarqube code-analyze over."
fi

最后

以上就是爱撒娇自行车为你收集整理的自动化代码质量检测平台 sonarqube gitlab-ci runner搭建docker 部署 sonarqubedocker 安装 gitlab-ci runner手动注册 gitlab-runner register 进行配置或者手动修改config.toml 进行配置centos7 安装 gitlab-ci runner的全部内容,希望文章能够帮你解决自动化代码质量检测平台 sonarqube gitlab-ci runner搭建docker 部署 sonarqubedocker 安装 gitlab-ci runner手动注册 gitlab-runner register 进行配置或者手动修改config.toml 进行配置centos7 安装 gitlab-ci runner所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(59)

评论列表共有 0 条评论

立即
投稿
返回
顶部