ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

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

2022-03-03 13:35:02  阅读:233  来源: 互联网

标签:git 项目 url 代码 gitlab 拉取 tensquare sonar 上传


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

目录

一:后端代码上传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

标签:git,项目,url,代码,gitlab,拉取,tensquare,sonar,上传
来源: https://www.cnblogs.com/zhijiyiyu/p/15959331.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有