-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathzathras.groovy
110 lines (86 loc) · 3.45 KB
/
zathras.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
// Zathras is responsible for maintaining the great machine.
// Manages creation and upkeep of seed jobs for each monitored repo.
//
// Setup as a free style job with webhook trigger on replay_ci
// Note: CI only supports repos on github currently.
// Note2: Credentials and git url case must match the github case as the webhook
// is case sensitive.
import groovy.json.JsonSlurper
// TODO: Remove owner/name and add projectUrl and base folder name?
// Once loading from json, sanity check that no repos use same base name.
// TODO: Support none monolythic repos without requiring subdir + _cores.txt
// -----------------------------------------------------------------------------
// Globals
// -----------------------------------------------------------------------------
def configuration = new HashMap()
def binding = getBinding()
configuration.putAll(binding.getVariables())
Boolean isProduction = configuration['PRODUCTION_SERVER'] ? configuration['PRODUCTION_SERVER'].toBoolean() : false
def repoDefaults = ['disabled': false, 'branch': 'master', 'testing': false, 'production': false]
// -----------------------------------------------------------------------------
// Main
// -----------------------------------------------------------------------------
out.println("Running on " + (isProduction ? "PRODUCTION" : "TEST") + " server.")
def jsonSlurper = new JsonSlurper()
def repoList = jsonSlurper.parseText(readFileFromWorkspace('repos.json'))
generateSeedJobs(repoList, repoDefaults, isProduction)
// -----------------------------------------------------------------------------
// Methods
// -----------------------------------------------------------------------------
def generateSeedJobs(repos, repoDefaults, isProduction) {
folder('seed_jobs_pipeline')
String seed_script = readFileFromWorkspace('jobs/seed_core_targets.groovy')
repos.each { repo_overrides ->
def repo = repoDefaults + repo_overrides
if (repo.disabled)
out.println("Skipping disabled repo: ${repo.name} (${repo.url}")
if ( (isProduction && !repo.production) || (!isProduction && !repo.testing) || repo.disabled)
return
String job_name = "seed_jobs_pipeline/${repo.owner}-${repo.name}-seeder"
createSeedJob(job_name, repo, seed_script, isProduction)
queue(job_name)
}
}
def createSeedJob(jobName, repo, seedScript, isProduction) {
pipelineJob(jobName) {
description("Seed job for ${repo.url}.")
parameters {
// REVIEW: Don't really want these as ui editable params, better option?
stringParam('param_repo_owner', repo.owner, 'Do NOT modify')
stringParam('param_repo_name', repo.name, 'Do NOT modify')
credentialsParam('param_repo_credential_id') {
description('Do NOT modify')
defaultValue(repo.credentialId)
}
stringParam('param_repo_url', repo.url, 'Do Not modify')
stringParam('param_repo_branch', repo.branch, 'Do Not modify')
}
definition {
cps {
script(seedScript)
sandbox()
}
}
properties {
pipelineTriggers {
triggers {
if (isProduction)
githubPush()
else {
pollSCM {
scmpoll_spec('*/2 * * * *')
}
}
}
}
}
// orphanedItemStrategy {
// // Trims dead items by the number of days or the number of items.
// discardOldItems {}
// defaultOrphanedItemStrategy {}
// }
logRotator {
numToKeep(20)
}
}
}