Add hook utility basic implementation

This commit is contained in:
wpetit 2019-03-19 16:07:47 +01:00
parent ec523ddfb4
commit 97aa9b61dd
1 changed files with 15 additions and 0 deletions

15
vars/hook.groovy Normal file
View File

@ -0,0 +1,15 @@
def call(String name) {
def rootDir = pwd()
def filepath = "${rootDir}/.jenkins/${name}.groovy"
def exists = fileExists(filepath)
if (!exists) {
println("No hook '${filepath}' script. Skipping.")
return
}
def hook = load(filepath)
if(hook.metaClass.respondsTo(hook, 'exec')) {
hook.exec()
} else {
error("Hook script '${filepath}' exists but does not expose an exec() function.")
}
}