sonarqube是什么,怎么连接gitlab,这里不介绍了,网上有。
这里总结网上没有的坑点避让,针对netcore项目的。
由sonarqube自动生成的CI/CD作业,有几点需要修改
1.镜像
“mcr.microsoft.com/dotnet/core/sdk:latest”
替换为
“bitnami/dotnet-sdk:latest”
为了支持最新的net6
2.修改apt的软件源为国内地址
CI/CD作业每次执行时都会进行apt-get update,并安装jre
这个步骤大概率会因为网络问题失败。
script部分,apt-update之前加上软件源地址修改步骤
例如
script:
- "echo \" \" > /etc/apt/sources.list"#清空内容
#追加内容
- "echo \"deb https://mirrors.aliyun.com/debian/ bullseye main non-free contrib\" >> /etc/apt/sources.list"
- "echo \"deb https://mirrors.aliyun.com/debian-security/ bullseye-security main\" >> /etc/apt/sources.list"
- "echo \"deb https://mirrors.aliyun.com/debian/ bullseye-updates main non-free contrib\" >> /etc/apt/sources.list"
- "echo \"deb https://mirrors.aliyun.com/debian/ bullseye-backports main non-free contrib\" >> /etc/apt/sources.list"
- "apt-get update"
3.设置全局字符编码为UTF8,防止出现文件名乱码
script中加入"export LANG=C.UTF-8"
4.结尾要指明调用的gitlab-runner
例如
tags:
- sonarqube#指定调用标签带有"sonarqube"的runner
完整参考
sonarqube-check:
image: bitnami/dotnet-sdk:latest
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:
- "echo \" \" > /etc/apt/sources.list"
- "echo \"deb https://mirrors.aliyun.com/debian/ bullseye main non-free contrib\" >> /etc/apt/sources.list"
- "echo \"deb https://mirrors.aliyun.com/debian-security/ bullseye-security main\" >> /etc/apt/sources.list"
- "echo \"deb https://mirrors.aliyun.com/debian/ bullseye-updates main non-free contrib\" >> /etc/apt/sources.list"
- "echo \"deb https://mirrors.aliyun.com/debian/ bullseye-backports main non-free contrib\" >> /etc/apt/sources.list"
- "apt-get update"
- "export LANG=C.UTF-8"
- "apt-get install --yes openjdk-11-jre"
- "dotnet tool install --global dotnet-sonarscanner"
- "export PATH=\"$PATH:$HOME/.dotnet/tools\""
- "dotnet sonarscanner begin /k:\"projectname_AYKfCTW9MSAanCnUxzW1\" /d:sonar.login=\"$SONAR_TOKEN\" /d:\"sonar.host.url=$SONAR_HOST_URL\" "
- "dotnet build"
- "dotnet sonarscanner end /d:sonar.login=\"$SONAR_TOKEN\""
allow_failure: true
only:
- master # or the name of your main branch
tags:
- sonarqube
netcore的工程文件需要设置取消生成多语言文件夹
特别是zh-hans,在linux下会引起大小写冲突
<PropertyGroup>
<SatelliteResourceLanguages>enSatelliteResourceLanguages>
PropertyGroup>