Jenkins+Docker+SpringCloud微服务持续集成(三)

2022/3/6 23:16:17

本文主要是介绍Jenkins+Docker+SpringCloud微服务持续集成(三),对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

链接:https://pan.baidu.com/s/1HR3Q-cojnCidRy1xrdlOxg
提取码:7m56
--来自百度网盘超级会员V3的分享

微服务持续集成(1)-项目代码上传到Gitlab
在IDEA操作即可,参考之前的步骤。包括后台微服务和前端web网站代码
image
image
image

先做后端提交
后端项目先提交给本地git
image
image
image

新定义远程仓库地址
image
image

复制gitlab中tensquare_back项目中http的URL

提交完成后,查看gitlab
image

Windows本地安装TortoiseGit(小乌龟)用来提交前端项目代码

安装中文汉化包

右击小乌龟git打开设置提交远程URL(前端项目的URL)
image
image

查看gitlab的tensquare_front项目
image

微服务持续集成(2)-从Gitlab拉取项目源码
1)创建Jenkinsfile文件

Jenkinsfile中的内容

点击查看代码
//git的凭证
def git_auth="1be38991-873b-4a68-8eb6-312347fdc0a4"
//git的URL
def git_url="git@192.168.195.180:devops_group/tensquare_back.git"
node {
    stage('pull code') {
        //切换成变量,字符串符号使用双引号
        checkout([$class: 'GitSCM', branches: [[name: "*/${branch}"]], extensions: [], userRemoteConfigs: [[credentialsId: "${git_auth}", url: "${git_url}"]]])
    }
}

在Jenkins服务器上查看构建项目
image

微服务持续集成(3)-提交到SonarQube代码审查
1)创建项目,并设置参数
创建tensquare_back项目,添加一个选择参数
image
image

每个项目的根目录下添加sonar-project.properties

点击查看代码
# must be unique in a given SonarQube instance
sonar.projectKey=tensquare_eureka_server
# this is the name and version displayed in the SonarQube UI. Was mandatory prior to SonarQube 6.1.
sonar.projectName=tensquare_eureka_server 
sonar.projectVersion=1.0

# Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows.
# This property is optional if sonar.modules is set. sonar.sources=. 
sonar.exclusions=**/test/**,**/target/** 
sonar.java.binaries=.
sonar.java.source=1.8 
sonar.java.target=1.8 

#sonar.java.libraries=**/target/classes/**
# Encoding of the source code. Default is default system encoding 
sonar.sourceEncoding=UTF-8

注意:修改sonar.projectKey和sonar.projectName

3)修改Jenkinsfile构建脚本

点击查看代码
//git的凭证
def git_auth="1be38991-873b-4a68-8eb6-312347fdc0a4"
//git的URL
def git_url="git@192.168.195.180:devops_group/tensquare_back.git"
node {
    stage('pull code') {
        //切换成变量,字符串符号使用双引号
        checkout([$class: 'GitSCM', branches: [[name: "*/${branch}"]], extensions: [], userRemoteConfigs: [[credentialsId: "${git_auth}", url: "${git_url}"]]])
    }
    stage('check code') {
            //定义SonarQubeScanner工具
            def scannerHome = tool 'sonar-scanner'
            //引用SonarQube系统环境
            withSonarQubeEnv('sonarqube') {
            sh """
                cd ${project_name}
                ${scannerHome}/bin/sonar-scanner
               """
               }
    }
}

再次构建进行代码检查

检查结果
image

随后把服务网关、认证中心和活动微服务都进行检查
image



这篇关于Jenkins+Docker+SpringCloud微服务持续集成(三)的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程