• sonarqube连接gitlab测试netcore项目的避坑点


    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"
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8

    3.设置全局字符编码为UTF8,防止出现文件名乱码
    script中加入"export LANG=C.UTF-8"
    4.结尾要指明调用的gitlab-runner
    例如

    tags:
        - sonarqube#指定调用标签带有"sonarqube"的runner
    
    • 1
    • 2

    完整参考

    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
    
    
    • 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
    • 26
    • 27
    • 28
    • 29

    netcore的工程文件需要设置取消生成多语言文件夹
    特别是zh-hans,在linux下会引起大小写冲突

    <PropertyGroup>
    		<SatelliteResourceLanguages>enSatelliteResourceLanguages>
      PropertyGroup>
    
    • 1
    • 2
    • 3
  • 相关阅读:
    算法金 | 必会的机器学习评估指标
    图片操作笔记-滤波-python
    阿里云云安全中心基础免费版不支持审计功能!
    学校项目培训之Carla仿真平台之Carla学习内容
    【MATLAB基础绘图第17棒】绘制玫瑰图
    谈一下相对位置编码
    Keras深度学习实战(25)——使用skip-gram和CBOW模型构建单词向量
    C# Thread.Sleep 不精准的问题以及解决方案
    ubuntu18.04 开机后黑屏,左上角光标(强制关机后)
    [附源码]java毕业设计校园超市进销存管理系统
  • 原文地址:https://blog.csdn.net/kw269937519/article/details/126358343