Lazy loaded image
Jenkins + Gitlab/Gitee
Words 1134Read Time 3 min
2024-4-1

一、安装配置Jenkins

1.1 安装Jenkins和插件

Windows 安装 Windows (jenkins.io)
  • Java: see the Java Requirements page
    • Supported Java versions
      Long term support (LTS) release
      Weekly release
      Java 11, Java 17, or Java 21
      2.426.1 (November 2023)
      2.419 (August 2023)
      Java 11 or Java 17
      2.361.1 (September 2022)
      2.357 (June 2022)
      Java 8, Java 11, or Java 17
      2.346.1 (June 2022)
      2.340 (March 2022)
      Java 8 or Java 11
      2.164.1 (March 2019)
      2.164 (February 2019)
树莓派/Ubuntu 安装jenkins https://pkg.jenkins.io/debian-stable/
  • This is the Debian package repository of Jenkins to automate installation and upgrade. To use this repository, first add the key to your system (for the Weekly Release Line):
    • Then add a Jenkins apt repository entry:
      • Update your local package index, then finally install Jenkins:
         
        安装 gitee 插件

        1.2 内网穿透

        参考 该文如何在树莓派上使用Nginx搭建本地站点并通过内网穿透实现远程访问 - cpolar 极点云官网,安装coplar并搭建隧道(连接到jenkins8080端口),实现内网穿透访问。
        要注意的是,以上步骤使用的是随机临时地址,该公网地址24小时内会随机变化。我们接下来为其配置固定地址,该地址不会变化,设置后将无需每天重复修改地址。因此需升级至基础套餐或以上才支持配置固定域名。
         
        notion image
        notion image

        1.3 其他

        1. git服务器 GitLab服务器搭建/gitee/github
        1. 安装 git
        1. 安装 cmake

        引用

        Jenkins 重启方法

        方法一:通过 Jenkins Web 界面

        1. 打开 Web 浏览器,并导航至 Jenkins 的网址,例如 http://localhost:8080(如果 Jenkins 正在本地运行)。
        1. 登录到 Jenkins 控制台。
        1. 点击右上角的用户名,然后选择 "Manage Jenkins"。
        1. 在左侧导航栏中,选择 "Manage Nodes and Clouds"。
        1. 在节点列表中,找到 "Master" 节点(通常是默认的),点击它。
        1. 在节点详情页面,点击左侧的 "Disconnect"(断开连接)按钮,然后再点击 "Connect"(连接),这会重启 Jenkins 服务。

        方法二:通过 Jenkins 命令行工具

        1. 打开命令提示符(cmd)或 PowerShell。
        1. 导航至 Jenkins 的安装目录。
        1. 运行以下命令来重启 Jenkins 服务:
          Jenkins:添加SSH全局凭证 - .NET开发菜鸟 - 博客园 (cnblogs.com)
          notion image

          二、基于 Jenkins+ Gitee/Gitlab/Gitee搭建CI/CD环境

          2.1 建立FreeStyle任务

          2.1.1 去除历史编译设置

          notion image

          2.1.2 源码管理配置

          notion image

          2.1.3 构建触发器

          notion image

          2.1.4 编译步骤

          2.2 构建流水任务

          2.2.1 Jenkisn 配置

          1. 选择流水线任务
          1. 创建任务
            1. 创建触发器(gitee webhook地址和密码在这里获取,gitee配置需要)
            2. notion image
              notion image
          1. 选择配置- 高级项目选项
            1. pipeline script
            2. 流水线语法
            3. 片段生成器
            4. checkout拉取代码(URL-用户名密码-选择分支)
              1. 报错:No ECDSA host key is known for
                打开 Manage jenkins --> Configure Global Security ,找到 Git Host Key Verification Configuration,按下图修改后保存。警告信息可以忽略
                notion image
            5. 生成流水线脚本
            6. 把脚本拷贝过来粘贴到这里
              1. notion image
          1. 立即构建
          1. 控制台输出 console output
          1. 直接在脚本这里写上编译命令
            1. notion image
          1. 立即构建
            1. notion image
           

          2.2.2 Gitee 配置

          管理
          notion image
          问题1:webhook404
          解决方法1:通用的webhook触发下载插件Generic Webhook Trigger,添加Token和jenkins登录密码[1]
          解决方法2:无需更改,只是gitee测试接口错误[2]
           

          三、 引入cppcheck实现静态检测

           

          四、引入脚本+htmlreport+email实现单元测试

           
           

          4.1 邮箱通知

          引用

          1. Jenkins
          1. 使用 GitLab + Jenkins 实现持续集成(CI)环境
          1. woker/集成测试环境搭建/手把手教你搭建Jenkins+Github持续集成环境
          1. Jenkins + Gitee 实现代码自动化构建 (超级详细)
           
          上一篇
          模板设计模式:让你的代码结构更清晰
          下一篇
          Guide to Linux System

          Comments
          Loading...