Custom build scripts trigger git

1. After a triggering event by gitee push, execution WebHooks request to the address we set
2. In the address setting request which determines whether the current commit that it contains a "need to automate compilation label", if included script compile the Linux implementation of the above automatic deployment projects
eg: the example given above is to determine that it contains the current commit 10086, if included Linux script execution

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
(value = "/common/run",method = RequestMethod.POST)
public ResponseEntity (HttpServletRequest request) throws ParseException {
try {
List<String> jsonList = org.apache.commons.io.IOUtils.readLines(request.getInputStream());
if (Objects.nonNull(jsonList) && jsonList.size()>0){
StringBuilder jsonBuilder = new StringBuilder();
jsonList.forEach(str->{
jsonBuilder.append(str);
});
JSONObject jsonObject = JSON.parseObject(jsonBuilder.toString());
JSONArray commitsJSONArray = (JSONArray)jsonObject.get("commits");
boolean flag = false;
for(int i=0,length = commitsJSONArray.size();i<length;i++){
JSONObject childJSONObject = (JSONObject) commitsJSONArray.get(i);
String message = (String) childJSONObject.get("message");
log.info("获取到commit里面的消息 {}",message);
if (message.contains("10086")){
flag = true;
}
}
log.info("flag的值{}",flag);
if (flag){
process(new String[]{"sh","/root/run.sh"});
}
}
} catch (Throwable throwable) {
throwable.printStackTrace();
}
return ResponseEntity.ok("执行完毕");
}

* 调用脚本
* @param cmdArray
* @throws Throwable
*/
protected void process(String[] cmdArray) throws Throwable {
ProcessBuilder pb = new ProcessBuilder(cmdArray);
pb.redirectErrorStream(true);
Process p = null;
BufferedReader br = null;
try {
p = pb.start();
br = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line = null;
log.info("Invoke shell: {}", StringUtils.join(cmdArray, " "));
while ((line = br.readLine()) != null) {
log.info(line);
}
p.waitFor();
} finally {
if (br != null) {
br.close();
}
if (p != null) {
p.destroy();
}
}
}

Original: Big Box  Custom build scripts trigger git


Guess you like

Origin www.cnblogs.com/petewell/p/11615215.html