git & gerrit & shell

g公司使用Gerrit改善评审流程. 比较麻烦.gerrit提交后会触发vertifyCI, 实施代码扫描.

这一堆过程, 打印出一堆信息, 都在log中, 所以处理log就需要自己写shell了.

ssh -p 29418 xxxxx@xxxxxx gerrit query --format=JSON --patch-sets --all-approvals --commit-message --comments change:3920147

#提取log中的http:// url, 取第一条
ssh -p 29418 xxxxx@xxxxxx gerrit query --format=JSON --comments change:3920147|head -n 1 | jq '.comments'|jq '.[] | .message'|grep -oh "https.*/" | head -n 1


#log

java -jar ~/bin/jenkins-cli.jar -s https://xxxxxxx/xxxxx/ -auth xxxxx:xxxxxx console jobName 472

其中用到几个工具, jq, 是一个解析json的工具, 功能非常强大:

jq

https://stedolan.github.io/jq/manual/#Basicfilters

https://www.cnblogs.com/bhlsheji/p/5345192.html

https://www.cnblogs.com/lurenjiashuo/p/bash-json-jq.html

gerrit query

https://gerrit-documentation.storage.googleapis.com/Documentation/2.13.7/cmd-query.html

https://gerrit-documentation.storage.googleapis.com/Documentation/2.13.7/json.html

另外关于正则表达式的贪婪非贪婪模式:

https://www.cnblogs.com/xudong-bupt/p/3586889.html

https://gerrit-documentation.storage.googleapis.com/Documentation/2.13.7/user-search.html

grep

grep 仅显示匹配部分,(默认是显示匹配到的行)

grep -oh "abc" xxx.log

abc可以为正则表达式

原文地址:https://www.cnblogs.com/tekikesyo/p/10947865.html