several practices relate with git

1 How to install git by “make”

编译基础环境环境和依赖的包


yum -y install gcc make

yum install -y curl curl-devel zlib-devel openssl-devel perl perl-devel cpio expat-devel gettext-devel

对于定制的一些系统,找不到依赖时,可能要修改repo源:http://mirrors.163.com/.help/centos.html:


wget http://mirrors.163.com/.help/CentOS6-Base-163.repo

如果遇到下载不了的,可以手工下载至/var/cache/yum/i386/6/base/packages类似目录

下载和安装:


wget   http://www.codemonkey.org.uk/projects/git-snapshots/git/git-latest.tar.xz

xz -d git-latest.tar.xz

tar -xvf git-latest.tar

cd git-2015-09-07/

autoconf

./configure

make && make install

 ln -s /usr/local/bin/git /usr/bin/git

批处理命令为:


wget   http://www.codemonkey.org.uk/projects/git-snapshots/git/git-latest.tar.xz; xz -d git-latest.tar.xz; tar -xvf git-latest.tar; cd git-2015-09-07; autoconf; ./configure; make && make install; ln -s /usr/local/bin/git /usr/bin/git

 2 Jenkins download git repository timeout error:

Jenkins使用git作为scm时,默认N多操作使用的都是10分钟作为timeout时间的设置,当git clone的repo太大,例如超过1G或下载速度太慢时,会download不了代码:

08:36:53 ERROR: Timeout after 10 minutes

所以要求助git jenkins插件的”Additional Behaviours“修改下timeout的时间以解决timeout问题:

1111111111nfig [Jenkins] - Google Chrome

3 How to download sub folder for GIT in jenkins:

当一个repository太大时,N个JOB如果没有共享workspace,则占用磁盘的空间为N*repo大小,而实际中,我们确实只需要git里面的某一个子目录而已,所以可以使用sparse checkout来解决,同样求助于Additional Behaviours来设置:

2222222222222

 

4  How to limit git scm poll change path limit:

使用GIT(Github.Gitlab,etc)的web hook的通知,可以让有代码改动时,通知到Jenkins job去自动执行,但是如果想限制某个目录的代码改动才触发Jenkins job,可以同样求助于Additional Behaviours:

hi

 

 5  Git Merge with remote host.


1006  git clone  https://jiafu@stash-eng-chn-sjc1 /git/stach.git

1023  git remote add remotename https://jiafu@stash-eng-chn-sjc1/git-fork/stach.git

1034  git fetch remotename /feature/930

1045  git merge remotename /feature/930

1046  git status

1061  git checkout -b gate/20161202

1051   fix conflict

1052  git add/commit

1053  git push remotename gate/20161202

6 保存密码

  $ git config --global credential.helper cache
  # 默认缓存密码15分钟,可以改得更长, 比如1小时
  $ git config --global credential.helper 'cache --timeout=3600'

Open source: xcov

Project :    https://code.google.com/p/xcov/

Short introduce:   enhance lcov-to-cobertura-xml to support converting gcov to coberuta and working with svn diff

Open source project lcov-to-cobertura-xml provide converting the lcov data to cobertura xml so that it can be easier integrated with Jenkins.

Thus, we have to handle the gcov data at first instead of lcov sometimes, What’s more, we only want to generate code coverage with svn code diff. So this tool enhance the lcov-to-cobertura-xml to support convert gcov data or work with svn diff file base on keeping the old features available.

Basic Usage:

Converts LCOV coverage data to Coberturacompatible XML for reporting. By default, XML output will be written to ./coverage.xml

xcov.py lcovfile.info
xcov.py lcov-file-1.info lcov-file-2.info
xcov.py lcov-file.info -s svndiffFilePath
xcov.py lcovfile.info -a srcPath:gcdaPath
xcov.py -a srcPath:gcdaPath
xcov.py lcovfile.info b src/dir e test.lib o path/out.xml

Options:

-h, –help show this help message and exit -b BASE_DIR, –base-dir=BASE_DIR

Directory where source files are located

-e EXCLUDES, –excludes=EXCLUDES

Comma-separated list of regexes of packages to exclude

-a SRCDSTPAIRS, –srcdstPairs=SRCDSTPAIRS

add src:dst path, the src path is source code path, the dst path is gcda/gcno path

-o OUTPUT, –output=OUTPUT

Path to store cobertura xml file

-w, –web

create html report

-d, –delete

delete the copied gcov data

-s, –svndiff

Path to store svn diff file path

By default

(1) gcdaPath=gcnoPath=objsPath

(2) XML output will be written to ./coverage.xml

(3) svndiffFilePath can be generated by svn diff command with option –summarize such as: svn diff -r {2014-05-01}:{2014-05-10} src/ –summarize > svndifffile.txt

Jenkins’ remote build methods

某些场景下,我们需要远程执行一个job, 例如和其他工具做集成时,符合某个条件之时立即触发job。涉及远程执行的帮助文档可以随意寻找一个job的url然后加上/api(例如http://[jenkins dns]/job/jobName/api)来获取帮助,按照是否启动security可以划分为两类情况:

1 未启动security

直接发Post请求    POST  http://[jenkins dns]/job/jobName/build

可使用工具curl来执行POST:

curl -X POST http://[jenkins dns]/job/jobName/build

2 启动security

2.1   不带用户名:令牌方式

(1)  在Build Trigger设置授权Token:例如设置为1234567890

111_2

(2) 使用POST请求  POST  http://[jenkins dns]/job/jobName/build?token=1234567890

 

 2.2  带用户名:curl等工具方式:

上面的方式无法看到是具体哪个用户执行的build, 所以可以采用curl的方式执行(类似的工具还有wget,但是本文未尝试),不过缺点是curl不定在每个操作系统上都配备(Windows默认没有)

加上用户名和密码使用方式如下:

curl -X POST http://username:password@ci.jenkins.com/job/jobName/build

执行之后可以看到由具体用户start.
Started by user jiafu
[EnvInject] - Loading node environment variables.
Building remotely on TA-Win7-64-07 in workspace c:/autotest/workspace/jobName
Finished: SUCCESS
2.3  带用户名:代码方式

可参考:https://wiki.jenkins-ci.org/display/JENKINS/Authenticating+scripted+clients

 

远程执行还有很多其他特性,比如设置过多久之后的delay,带参数等等,本文不一一列举。