当前位置: 首页 > news >正文

DevOps(四)

CD(二)

    • 1. CD
      • Step 1 - 上传代码
      • Step 2 - 下载代码
      • Step 3 - 检查代码
      • Step 4 - 编译代码
      • Step 5 - 上传仓库
      • Step 6 - 下载软件
      • Step 7 - 制作镜像
      • Step 8 - 上传镜像
      • Step 9 - 部署服务
    • 2. 整体预览
      • 2.1 预览
        • 1. 修改代码
        • 2. 查看sonarqube检查结果
        • 3. 查看nexus仓库
        • 4. 查看harbor仓库
        • 5. 整体效果
      • 2.2 pipeline完整版
    • 3. 写在最后...

在这里插入图片描述

1. CD

参考前面的流程图,我们正式开始CD的流程

Step 1 - 上传代码

  • 安装git
    参考 Windows安装Git图文教程
  • 配置IDEA
    参考 IDEA配置Git,以GitHub远程仓库为例
  • 提交代码到本地 Commit
  • gitlab账号密码:root/Newm123@
    在这里插入图片描述
  • gitlab创建项目,复制URL
    在这里插入图片描述
  • IDEA push代码
    会提示输入gitlab URL 账号密码在这里插入图片描述
  • 提交完成
    在这里插入图片描述

Step 2 - 下载代码

  • 在jenkins上创建pipeline项目
    在这里插入图片描述
  • 创建节点,并连接节点
    在这里插入图片描述
    在这里插入图片描述
  • 配置jenkins gitlab(不配置也可以,因为我们在pipeline中也需要配置)
    Dashboard > Manage Jenkins >System
    在这里插入图片描述
  • 配置触发器(不配置也可以,在pipeline中也可以配置)
    在这里插入图片描述
  • pipeline片段
pipeline {agent { node { label 'node-133'}}stages {stage('Build') {steps {// Get some code from a GitHub repositorygit credentialsId: 'd3cb7c68-63e5-46d6-a505-d73a89902758', url: 'http://192.168.17.132:8929/devs/myjava.git'// Run Maven on a Unix agent.sh "mvn -Dmaven.test.failure.ignore=true clean package"// To run Maven on a Windows agent, use// bat "mvn -Dmaven.test.failure.ignore=true clean package"}}}
}

此处把mvn打包也一同配置了,并进行简单测试
在这里插入图片描述

[root@node-133 MyJava-Pipeline]# ll target/
total 4
drwxr-xr-x 2 root root   29 Jul 19 05:25 classes
drwxr-xr-x 3 root root   25 Jul 19 05:25 generated-sources
drwxr-xr-x 2 root root   28 Jul 19 05:25 maven-archiver
drwxr-xr-x 3 root root   35 Jul 19 05:25 maven-status
drwxr-xr-x 4 root root   54 Jul 19 05:25 MyJava-latest
-rw-r--r-- 1 root root 3054 Jul 19 05:25 MyJava-latest.war
[root@node-133 MyJava-Pipeline]# pwd
/opt/jenkins/workspace/MyJava-Pipeline

Step 3 - 检查代码

  • 启动sonarqube,登录并设置密码
    http://192.168.17.133:9090
    admin/password
    在这里插入图片描述
  • 部署sonar-scanner
unzip sonar-scanner-cli-4.7.0.2747-linux.zip
cd sonar-scanner-4.7.0.2747-linux/
vim conf/sonar-scanner.properties
[root@dbc-server-554 sonar-scanner-4.7.0.2747-linux]# cat conf/sonar-scanner.properties
#Configure here general information about the environment, such as SonarQube server connection details for example
#No information about specific project should appear here#----- Default SonarQube server
sonar.host.url=http://localhost:9090#----- Default source code encoding
sonar.sourceEncoding=UTF-8
ln -sv /root/docker/sonar/sonar-scanner-4.7.0.2747-linux /usr/local/sonar-scanner
export PATH=/usr/local/sonar-scanner/bin:$PATH
source .bashrc
[root@dbc-server-554 sonar-scanner-4.7.0.2747-linux]# sonar-scanner -h
INFO:
INFO: usage: sonar-scanner [options]
INFO:
...
  • 生成扫描命令
    在这里插入图片描述
mvn clean verify sonar:sonar \-Dsonar.projectKey=MyJava \-Dsonar.host.url=http://192.168.17.133:9090 \-Dsonar.login=6b1dddd3274606082753ff907ee1b0380c28298a

部署jenkins pipeline

  • pipeline片段
//定义http方法
def HttpReq(reqType,reqUrl,reqBody){sonarServer = "http://192.168.17.133:9090/api"// 可以不加authentication认证,因为默认不需要result = httpRequest  consoleLogResponseBody: true, httpMode: 'GET',responseHandle: 'NONE', url: "${sonarServer}/${reqUrl}"                   //                customHeaders:[[name:'Authorization', value:"Basic ${credentials}"]]return result
}//获取Sonar质量阈状态
def GetProjectStatus(projectName){apiUrl = "project_branches/list?project=${projectName}"response = HttpReq("GET",apiUrl,'')response = readJSON text: """${response.content}"""result = response["branches"][0]["status"]["qualityGateStatus"]println(response)return result
}pipeline 
http://www.lryc.cn/news/102374.html

相关文章:

  • Element-plus侧边栏踩坑
  • 支持多种通信方式和协议方便接入第三方服务器或云平台
  • 使用 OpenCV 进行图像模糊度检测(拉普拉斯方差方法)
  • 神经网络简单介绍
  • 16位S912ZVML32F3MKH、S912ZVML31F1WKF、S912ZVML31F1MKH混合信号MCU,适用于汽车和工业电机控制应用。
  • 力扣 509. 斐波那契数
  • 使用 DolphinDB TopN 函数探索高效的Alpha因子
  • 超聚变和厦门大学助力兴业银行构建智慧金融隐私计算平台,助力信用卡业务精准营销...
  • docker 的compose安装
  • JavaScript---事件对象event
  • Day 15 C++对象模型和this指针
  • HarmonyOS/OpenHarmony元服务开发-卡片生命周期管理
  • 软件工程01
  • UML/SysML建模工具更新(2023.7)(1-5)有国产工具
  • Mac plist文件
  • 基于Java+SpringBoot+vue前后端分离校园周边美食探索分享平台设计实现
  • 【openwrt】package介绍
  • vue 封装一个鼠标拖动选择时间段功能
  • ubuntu22.0安装Barrier局域网共享鼠标键盘
  • ffmpeg常用功能博客导航
  • shopee,lazada,etsy店群如何高效安全的管理
  • 【计算复杂性理论】证明复杂性(八):命题鸽巢原理(Propositional Pigeonhole Principle)的指数级归结下界
  • 使用DataX实现mysql与hive数据互相导入导出
  • 语音转录成文本:AI Transcription for mac
  • [nlp] TF-IDF算法介绍
  • 一些感想,写在8月之前
  • 推动数字经济高质量发展需破解三大挑战
  • Pycharm工具Python开发自动添加注释(详细)
  • RUST 有哪些整型?
  • 【Python 实战】---- 批量识别图片中的文字,存入excel中【使用百度的通用文字识别】