Jeknins API 调用

  1. 创建用户API Token

    image-20210404225621042

  2. Jenkins 系统设置中设置未授权用户可以读访问

    技术分享

技术分享

  1. 调用视图View接口返回该视图下所有JOBS

    http://192.168.31.85:9001/view/test/api/json?tree=jobs[name,url,inQueue,color,lastBuild[number,building,duration,estimatedDuration,result,url]]

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
{
"_class": "hudson.model.ListView",
"jobs": [
{
"_class": "hudson.model.FreeStyleProject",
"name": "News-Spider",
"url": "http://192.168.31.85:9001/job/News-Spider/",
"color": "blue",
"inQueue": false,
"lastBuild": {
"_class": "hudson.model.FreeStyleBuild",
"building": false,
"duration": 19222,
"estimatedDuration": 24315,
"number": 193,
"result": "SUCCESS",
"url": "http://192.168.31.85:9001/job/News-Spider/193/"
}
},
{
"_class": "hudson.model.FreeStyleProject",
"name": "Zhihu-Notify",
"url": "http://192.168.31.85:9001/job/Zhihu-Notify/",
"color": "blue",
"inQueue": false,
"lastBuild": {
"_class": "hudson.model.FreeStyleBuild",
"building": false,
"duration": 2446,
"estimatedDuration": 2765,
"number": 904,
"result": "SUCCESS",
"url": "http://192.168.31.85:9001/job/Zhihu-Notify/904/"
}
},
{
"_class": "hudson.model.FreeStyleProject",
"name": "Zhihu-Spider",
"url": "http://192.168.31.85:9001/job/Zhihu-Spider/",
"color": "blue",
"inQueue": false,
"lastBuild": {
"_class": "hudson.model.FreeStyleBuild",
"building": false,
"duration": 126009,
"estimatedDuration": 132518,
"number": 3613,
"result": "SUCCESS",
"url": "http://192.168.31.85:9001/job/Zhihu-Spider/3613/"
}
}
]
}