Jenkins/vars/hook.groovy

20 lines
584 B
Groovy
Raw Permalink Normal View History

2019-03-19 16:07:47 +01:00
def call(String name) {
2022-09-21 11:26:40 +02:00
def filepath = "${env.WORKSPACE}/.jenkins/${name}.groovy"
2019-03-19 16:07:47 +01:00
def exists = fileExists(filepath)
if (!exists) {
println("No hook '${filepath}' script. Skipping.")
return
}
def hook = load(filepath)
if (hook == null) {
error("Hook '${filepath}' seems to be null. Did you forget to add 'return this' at the end of the script ?")
}
2022-09-20 16:28:03 +02:00
if (hook.metaClass.respondsTo(hook, 'exec')) {
2019-03-19 16:07:47 +01:00
hook.exec()
} else {
error("Hook script '${filepath}' exists but does not expose an exec() function.")
}
2022-09-20 16:28:03 +02:00
}