微服务持续集成之 代码上传,拉取,和代码审查

微服务持续集成之 代码上传,拉取,和代码审查

一:后端代码上传gitlab

登录gitlab,新建两个项目,一个tensquare_font用于前端,一个tensquare_back用于后端

image-20220301111857495

image-20220301111943038

image-20220301112056725

进入idea的后端项目,将整个后端项目提交到本地

image-20220301112358946

image-20220301112436322

选择整个项目,右击--->Git--->Repository--->Remotes

image-20220301112548005

在弹出的对话框,如果有远程地址,则点击 减号- ,先删除,然后在点击 + 加号,添加新的仓库地址

仓库地址的URL,为gitlab上,后端项目的http 方式的url地址

image-20220301112832166

image-20220301112807896

然后,在将后端项目推送到gitlab上

image-20220301113117266

image-20220301113129771

可以在gitlab上的后端项目查看到我们刚才推送的项目

image-20220301113152678

二:windows本地安装TortoiseGit 提交前端代码

链接:https://pan.baidu.com/s/1Dg2lGS1lR_3wkMN_hFGobw?pwd=x8pt
提取码:x8pt

TortoiseGit为安装包,TortoiseGit-LanguagePack 为语言包

安装TortoiseGit,安装时,全部默认即可

image-20220301114338306

安装完毕后,跳出对话框,要我们选择语言。此时只有English,所以,我们先点击取消

image-20220301114031708

安装中文包,还是全部默认

image-20220301114114140

找到前端的项目文件夹右击,---->TortoiseGit---->设置

image-20220301114617369

远端-->配置远端gitlab仓库的名字,和URL(URL为gitlab上,前端项目的http方式的url)

image-20220301115100375

image-20220301114733628

配置好远端仓库后,再次右击前端项目---->TortoiseGit--->推送

image-20220301115233860

确认推送的远端仓库,无误后点击确认

image-20220301115411983

输入gitlab的用户名和密码

image-20220301115538797

点击项目,右击---->Git 提交到master

image-20220301163907473

image-20220301164023253

右击项目,-->TortoiseGit-->推送 ,将本地的项目推送到gitlab上

image-20220301164407590

image-20220301115621929

在gitlab的前端项目tensquare_font,已经可以看到我们推送的前端项目了

image-20220301164254606

三:从gitlab拉取源代码

在Jenkins新建一个项目,项目名tensquare_back,选择pipeline的方式

image-20220301115946543

选择参数化构建This project is parameterized --->ADD--->String Parameter

Name: branch

Default Value: master

Description: 请输入分支

image-20220301120306873

使用scm方式

image-20220301121252590

在idea里编写Dockerfile文件(如果原来有,修改或删除),并提交

//定义git凭证
def git_url="git@192.168.23.201:my_group/tensquare_back.git"
//定义git的url
def git_auth="fc529390-8711-4c3a-894e-fd77845bf5e4"


node {
    stage('pull code'){
    checkout([$class: 'GitSCM', branches: [[name: '*/master']], extensions: [], userRemoteConfigs: [[credentialsId: "${git_auth}", url: "${git_url}"]]])
    }
}

image-20220301122255595

在Jenkins上,构建后端项目

image-20220302195558152

拉取代码,构建成功,并且可以在Jenkins服务器器上查看到项目

image-20220302195945548

在/var/lib/jenkins/workspace目录下,可以看到项目目录tensquare_back

image-20220302200141966

四,提交到SonarQube 代码审查

修改tensquare_back项目,添加选择参数

This project is parameterized--->Add Parameter--->Choice Parameter ?

image-20220302200443562

填写参数名和参数可选项

project_name:   projeckt_name

Choise:  tensquare_eureka_server
					tensquare_zuul
					tensquare_admin_service
					tensquare_gathering
					
Description: 注册中心
							服务网关
							认证中心
							活动微服务

image-20220302214100179

image-20220302201141193

在idea 的 每个项目(除了common工具) 的项根目录下,添加sonar-project.properties文件名不要写错名字不要写错。

eureka 项目的如下。 每个项目要注意修改 projeckKey 和 projectName,修改为和每个项目一样

# 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

image-20220302202551729

修改Jenkinsfile 构建脚本添加代码检查步骤

image-20220302203224207

//定义git凭证
def git_url="git@192.168.23.201:my_group/tensquare_back.git"
//定义git的url
def git_auth="fc529390-8711-4c3a-894e-fd77845bf5e4"


node {
    stage('pull code'){
    checkout([$class: 'GitSCM', branches: [[name: '*/master']], extensions: [], userRemoteConfigs: [[credentialsId: "${git_auth}", url: "${git_url}"]]])
    }
    stage('check code'){
            //定义SonarQubeScanner工具,要和Jenkins的全局工具配置里的一致
            def scannerHome = tool 'sonar-scanner'
            //引用SonarQube系统环境
            withSonarQubeEnv('sonarqube') {
            sh """
                cd ${project_name}
                ${scannerHome}/bin/sonar-scanner
               """
               }
    
    }
}

image-20220302203432193

image-20220302203723007

image-20220302214335977

image-20220302213256960

将更改后的sonar-project。properities和Jenkinsfile 进行提交

image-20220302213617311

构建后,多了 检查代码 步骤

image-20220302214921720

image-20220302214943193

四个服务都构建后,登录sonarqube 服务器查看

image-20220302215317923

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值