git+gerrit+jenkins+sonar 持续集成开发环境搭建

1:安装git

yum -y install git

安装成功之后:git version 1.8.3.1

2:安装apache

yum install httpd –y

service httpd start

/bin/systemctl stop httpd.service

将apache服务添加到开机 自启动

[root@localhost ~]# systemctl start httpd
[root@localhost ~]# systemctl enable httpd

https://blog.csdn.net/shj_php/article/details/79495861

3:安装ftp服务,方便传输文件

https://www.cnblogs.com/zhi-leaf/p/5983550.html

  • win下: ftp://192.168.2.137/pub/
  • linux下: /var/ftp/pub

4:安装java环境

https://blog.csdn.net/weixin_43893397/article/details/102636437

我这里安装的是 java 8

/usr/java/jdk1.8.0_251/

5:安装gerrit

参考文档: https://blog.csdn.net/lxbwolf/article/details/80174020http://www.mamicode.com/info-detail-339607.html

  • 注意:我这里数据库使用的默认H2数据库,mysql当时没有配置成功,一直无法关联

htpasswd -cm /home/gerrit/passwords admin 地址:192.168.2.137:1998 用户名:admin 密码:admin

启动停止指令: /home/gerrit/gerrit/bin/gerrit.sh start

chown gerrit:gerrit passwords 遇到问题:

Permission denied: [client 192.168.1.14:56363] AH01620: Could not open password file: /home/gerrit/passwords, referer: http://192.168.2.137:1998

解决方法:修改/home/gerrit/ 整个文件夹的读写权限

httpd.conf的配置

记得增加监听端口

Listen 80
Listen 1998

    ServerName v3server
    ProxyRequests Off
    ProxyVia Off
    ProxyPreserveHost On


    
        Order deny,allow  
        Allow from all  
    


    
        AuthType Basic
        AuthName "Gerrit Code Review"
        Require valid-user
        AuthUserFile /home/gerrit/passwords
    


    ProxyPass / http://192.168.2.137:8081/
    ProxyPassReverse / http://192.168.2.137:8081/


etc/gerrit.config配置文件

[gerrit]
        basePath = git
        canonicalWebUrl = http://192.168.2.137:80
        serverId = 905a197d-3c7e-41ec-8ffa-b71660d44c85
[container]
        javaOptions = "-Dflogger.backend_factory=com.google.common.flogger.backend.log4j.Log4jBackendFactory#getInstance"
        javaOptions = "-Dflogger.logging_context=com.google.gerrit.server.logging.LoggingContext#getInstance"
        user = gerrit
        javaHome = /usr/java/jdk1.8.0_251/jre
[index]
        type = lucene
[auth]
        type = HTTP
[receive]
        enableSignedPush = false
[sendemail]
        smtpServer = localhost
[sshd]
        listenAddress = *:29418
[httpd]
        listenUrl = http://*:8081/
[cache]
        directory = cache

  • 配置了反向代理,重启apache时报错: Invalid command 'ProxyRequests', perhaps misspelled or defined by a module not included in the server configuration 开启一下代理模块 运行一下
a2enmod proxy

再重启即可

安装完成之后,我这边一直提示无法 git push到远程地址

  1. 将资料中的 commit-msg 文件放在/gerrit/cfg/.git/hooks/
  2. 执行资料中的init_repo.sh
./init_repo.sh

内容如下:

#!/bin/bash
set -e

CODEBASE=$( dirname $( readlink -f ${0} ) 2> /dev/null|| echo ${PWD} )

gitdir=$(git rev-parse --git-dir)
test -e ${gitdir}/hooks/pre-commit || cp ${gitdir}/hooks/pre-commit.sample ${gitdir}/hooks/pre-commit

test -e ${gitdir}/hooks/commit-msg || cp $CODEBASE/misc/commit-msg ${gitdir}/hooks/commit-msg

git config remote.origin.push HEAD:refs/for/master

echo "Gerrit code review is ready"

如果出现错误: [remote rejected] HEAD -> refs/for/master (no common ancestry)

git pull --rebase origin master

  1. git add -A
  2. git commit --amend //如果需要重新生成 commit ID,需要删除此步骤文件中的ID整行
  3. git push // git push origin HEAD:refs/for/master

6:安装jenkins

https://blog.csdn.net/yangzaizi/article/details/83505026

安装jenkins最好安装 jenkins-2.164.3-1.1.noarch.rpm以上的,要不然安装插件的时候会比较麻烦,低版本自带的插件好多无法安装 。但是太高的版本需要java 11的环境,所以安装的时候选个好的版本,可以省掉很多麻烦事情

遇到问题: 报错:Starting Jenkins bash: /usr/bin/java: 没有那个文件或目录 参考:https://blog.csdn.net/m0_37564404/article/details/99942264

sudo service jenkins start

jenkins:http://192.168.2.137:1998/

账号:admin 密码:admin

在线安装插件 gerrit trigger

jenkins的邮件通知配置

SMTP服务: 用户名:[email protected] 密码:123456

遇到问题:配置gerrit servers时出现 jenkins "/root/.ssh/id_rsa" does not exist. 可参考下文:https://www.optbbs.com/thread-5965823-1-1.html 本次操作无法解决,我将 /root/.ssh/id_rsa 复制到 /var/lib/jenkins/.ssh/ 下 记得以后新用户生成sshkey后,做同样操作

浏览器地址:http://192.168.2.137:8080/

7:发布流程,Apache文件浏览功能

https://blog.51cto.com/adelazhu/1681512

8:FTP环境搭建

https://blog.csdn.net/wangxintong_1992/article/details/81194544

1056 - useradd xiao

1057 - passwd xiao

1058 - mkdir /var/www/xiao

1059 - usermod -d

/var/www/xiao xiao

设置用户访问固定的路径 https://www.cnblogs.com/xiaofeng028/p/3957147.html

9:sonar安装

需要安装SonarQube和sonar-scanner,参考文档如下:https://blog.csdn.net/weixin_40816738/article/details/90111803

默认是不支持c和c++的,需要安装额外的插件 sonar我这边暂时还没有安装完成

sonar: ./sonar.sh start chown -R sonarUser:sonarUser /home/work/sonarqube-6.7.7

su - sonarUser /home/work/sonarqube-6.7.7/bin/linux-x86-64/sonar.sh stop 192.168.2.136:9000 注意:sonar的匹配的java版本和数据库类别和版本

 

文中所需软件,请参考 本人的资料,谢谢

你可能感兴趣的:(开发环境搭建,车载嵌入式)