-
Notifications
You must be signed in to change notification settings - Fork 67
/
scriptler.groovy
executable file
·48 lines (40 loc) · 1.27 KB
/
scriptler.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
#!./lib/runner.groovy
// Generates index for scriptler scripts
import net.sf.json.*
def repository = 'https://github.com/jenkinsci/jenkins-scripts'
def branch = 'main'
def json = [];
def dir = new File("./jenkins-scripts");
void git(File workingDir, String... commands) {
commands.each { cmd ->
def fullCommand = "git -C $workingDir.canonicalPath $cmd"
print "Executing \"${fullCommand}\"..."
fullCommand.execute().waitFor()
println ' done'
}
}
if (dir.isDirectory() && new File(dir, ".git").isDirectory()) {
git dir,
"fetch origin $branch",
"checkout origin/$branch"
} else {
dir.mkdirs()
git dir, "clone $repository . -b $branch"
}
def scriptlerDir = new File(dir, "scriptler")
scriptlerDir.eachFileMatch(~/.+\.groovy/) { File f ->
if(f.name.equals('testMetaFormat.groovy')) {
return
}
def m = (f.text =~ /(?ms)BEGIN META(.+?)END META/)
if (m) {
try {
def metadata = JSONObject.fromObject(m[0][1]);
metadata['script'] = f.name
json << metadata
} catch (Exception e) {
e.printStackTrace(System.err);
}
}
}
lib.DataWriter.write("org.jenkinsci.plugins.scriptler.CentralScriptJsonCatalog",JSONObject.fromObject([list:json]));