CI使用文档
Git使用
1. Git pull远程与本地文件冲突
具体方法如下
git pull origin V250_CS # 出现错误
git stash # 缓存起来
git pull origin # 分支
git stash pop # 还原
git stash clear
2. git部署全局hooks
init.templatedir
Specify the directory from which templates will be copied. (See the "TEMPLATE DIRECTORY"section of git-init(1).)
mkdir -p ~/.git_template/hooks
cp commit-msg ~/.git_template/hooks
git config --global init.templatedir ~/.git_template
3. git提交模板
commit.template
Specify a file to use as the template for new commit messages. “~/” is expanded to the value of $HOME and “~user/” to the specified user’s home directory.
git config --global commit.template ~/.gitmsg
4. git设置默认编辑器
git 默认编辑器为nano
if [ -e "/usr/bin/vim" ]; then
git config --global core.editor vim
else
git config --global core.editor vi
fi
5. url替换
url.<base>.insteadOf
Any URL that starts with this value will be rewritten to start, instead, with <base>. In cases where some site serves a large number of repositories, and serves them with multiple access methods, and some users need to use different access methods, this feature allows people to specify any of the equivalent URLs and have git automatically rewrite the URL to the best alternative for the particular user, even for a never-before-seen repository on the site. When more than one insteadOf strings match a given URL, the longest match is used.
6.查看文件修改历史
git log filename
可以看到fileName相关的commit记录git log -p filename
可以显示每次提交的diff- 只看某次提交中的某个文件变化,可以直接加上fileName
git show c5e69804bbd9725b5dece57f8cbece4a96b9f80b filename
- 文件追溯 (git blame),用于查看文件内容的引入
git blame filename
,
如果只想查看某几行的代码的代码git blame -L m,n filename
,- e.g :
git blame -L 5,+4 t.cpp
orgit blame -L 2,13 t.cpp
- e.g :
7. gitignore配置
ignore文件在最初时配置,不要在git push后设置
配置语法:
1、配置语法:
- 以斜杠“/”开头表示目录;
- 以星号“*”通配多个字符;
- 以问号“?”通配单个字符
- 以方括号“[]”包含单个字符的匹配列表;
- 以叹号“!”表示不忽略(跟踪)匹配到的文件或目录;
- 此外,git 对于 .ignore 配置文件是按行从上到下进行规则匹配的,意味着如果前面的规则匹配的范围更大,则后面的规则将不会生效;
cpipe工程ignore配置
*.o
*.d
*.d.[0123456789]*
*.swp
*.bin
*.suo
*.obj
*.tlog
*.log
*.lastbuildstate
*.unsuccessfulbuild
*.sdf
*.opensdf
*.exe
*.ilk
*.pdb
*.pnm
*.yuv
*.m
*.user
*.db
*.ipch
*.iobj
*.ipdb
*.exp
*.tmp
*.opendb
*.raw
# Build results
[Dd]ebug/
[Rr]elease/
# Visual Studio 2015/2017 cache/options directory
.vs/
*.gcno
8. 出现 * (no branch)的处理
如果当前正工作在(no branch)上:
git checkout -b <working branch>
,就会把(no branch)上的东西checkout到<working branch>
分支
如果不小心从(no branch)branch切换到其他分支了,用 git log
不能查找到(no branch)的信息,不要担心,先用 git reflog
查到(no branch)的commit,然后:
git checkout -b backup commit
Gerrit使用
配置环境
- 安装Git。
- 安装TortoiseGit。
- 打开Git Bash,运行
curl -O http://10.69.192.132:8080/static/init-cpipe-env-new.sh && chmod +x init-cpipe-env-new.sh && bash init-cpipe-env-new.sh <your domain user name>
。
所有安装按照提示运行即可。
添加工程
-
登录Gerrit,打开Gerrit Project页面。可以看到页面上显示的是当前正在使用的所有Project。
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-tueYvRbN-1578301151548)(assets/Gerrit-Project.jpg)] -
选中
Create New Project
来创建一个新的工程。- 在
Project Name
中填入你想创建的工程名称 - 在
RIghts Inherit From
中选中All-Projects
作为权限控制的继承。 - 选中
Create initial empty commit
复选框。 - 点击
Create Project
工程就创建完成了。
- 在
-
工程创建完成后,默认只有master分支,并且没有任何代码。
添加分支
- 登录Gerrit,打开Gerrit Project页面。在所有工程中选择你想要添加分支的工程。就会进入分支显示页面。
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-74XdpRfz-1578301151549)(assets/Gerrit-Branch.jpg)] - 在
Branch Name
中填入想要添加的新分支名,在Initial Reviesion
中填入分支的代码基础版本。(这个基础版本可以是分支名或者是某一次提交的commit-id名) - 分支创建完成之后需要配置权限。选中
Access
就能进入分支的权限配置页面。
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-WWayF5aB-1578301151549)(assets/Gerrit-Access.jpg)] - 分支创建后有两个权限需要配置。一个是
refs/for/*
,一个是refs/heads/*
。refs/for/*
是用来进行代码提交的,只需要进行Push权限的配置。refs/heads/*
是代码实际存在的分支,需要进行Read权限配置,来控制谁能够下载代码。
还需要进行Label Code-Review权限配置,来控制谁能对代码进行+1 +2操作。Submit权限配置,控制谁能够把代码合入。- 所有的权限配置既可以使用通配符
*
来控制所有分支,也可以通过写具体分支名来控制具体的分支。控制方式视策略而定。 - 因为所有工程的权限配置都是继承自
All-Projects
,所有在All-Projects
配置的权限都会在所有工程中生效。(Label Verified
的权限就是在All-Projects
中配置的。)
- 如果需要对新添加的分支添加跑图用例。请跳转到添加跑图用例。
- 如果需要对新添加的分支添加自动合入到SVN功能。请跳转到添加SVN同步工程。
Jenkins使用
哈哈
添加跑图用例
-
找到Jenkins服务器上的
userContent\RemoteBatch\
文件夹。打开Gerrit_Trigger.json
文件,在result
Key下添加你想要的添加用例的分支。
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-jW0TtfSX-1578301151550)(assets/Jenkins-GerritTrigger.jpg)]- 1.代表Gerrit Project
- 2.代表Gerrit Branch
- 3.代表该分支对应的跑图配置。
-
在
userContent\RemoteBatch\result\
文件夹在添加对应名称的配置文件。配置文件的配置方法和离线的跑图脚本一致。唯一不一致的地方为多了一个bat_parameter
。
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-3TKf1vm3-1578301151550)(assets/Jenkins-batParameters.jpg)]- CPIPE_FOLDER 表示包含有makefile文件的文件夹名。每个Project的名称都不一样。
- VS_PROJ 表示包含有cpipe_fwk_vc.sln文件的文件夹名。每个VS版本的文件夹名不一致。
- BYPASS_BUILD 表示是否bypass各种build方式。
cygwin vs vs_debug vs_x64 vs_x64_debug bypass_build 1 0 0 0 0 1 0 1 0 0 0 2 0 0 1 0 0 4 0 0 0 1 0 8 0 0 0 0 1 16 - SQL_TABLE 为保留参数。不要改动。
- enable_codecheck 表示是否打开各种静态检查。默认1(使用cppcheck检查)。
- IMG_FOLDER 表示当前配置文件的所有验证图片从哪里取。该参数是相对于
userContent\testimages\
的相对路径。
-
在第二步配置的IMG_FOLDER目录下配置好测试图片。
添加SVN同步工程
- 打开Jenkins网页,选择
新建Item
来新建一个SVN同步工程。 - 输入任务名称,选择复制一个已经存在的SVN同步任务。
- 在参数列表中修改 CPIPE_FOLDER SVN_PATH SVN_USERNAME SVN_PASSWORD 的参数为新分支所使用的名称。
- 修改源码管理中的
Repository URL
为新分支的下载代码。 - 修改Gerrit Trigger中的想要触发的Project名和Branch名。
- 修改构建后操作中的邮件地址。
- 保存后,一个新的SVN同步工程就构建完成。