-
Notifications
You must be signed in to change notification settings - Fork 24
/
JobsGenerator.groovy
83 lines (72 loc) · 1.83 KB
/
JobsGenerator.groovy
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// To be run with Job DSL Plugin
// https://wiki.jenkins-ci.org/display/JENKINS/Job+DSL+Plugin
// https://jenkinsci.github.io/job-dsl-plugin/
def myJobs = [
'My Aborted Job' : jobDefinition(result: 'ABORTED'),
'My Building Job' : jobDefinition(result: 'UNSTABLE', queueJob: false, build: "sh 'sleep 300'"),
'My Failing Job' : jobDefinition(result: 'FAILURE'),
'My New Job' : jobDefinition(result: 'ABORTED', queueJob: false),
'My Stable Job' : jobDefinition(result: 'SUCCESS'),
'My Unstable Job' : jobDefinition(result: 'UNSTABLE'),
'yet-another-jenkins-notifier': yajnJob()
]
def myFolderName = 'My Folder'
def jobDefinition(Map args) {
{ name ->
pipelineJob(name) {
definition {
cps {
script("""
node {
stage 'Build'
${args.build ?: "echo 'Building'"}
stage 'Result'
currentBuild.result = '${args.result}'
}""")
sandbox()
}
}
}
if (args.queueJob != false) {
println "Add job $name to queue"
queue(name)
}
}
}
def yajnJob() {
{
name ->
multibranchPipelineJob(name) {
branchSources {
git {
remote('https://github.com/ggirou/yet-another-jenkins-notifier.git')
}
}
}
queue(name)
}
}
// Now create myJobs and views
folder(myFolderName) {
displayName(myFolderName)
}
myJobs.each { name, jobDefinition ->
jobDefinition(name)
jobDefinition("$myFolderName/$name")
}
listView("$myFolderName/All branches") {
description('All branches myJobs from sub-folders')
recurse()
jobs {
regex('.+/.+')
}
columns {
status()
weather()
name()
lastSuccess()
lastFailure()
lastDuration()
buildButton()
}
}