I am working on a global library for my Jenkins installation. My function should read from an external vault and return a secret which will be used inside the body of the function.
Basically, I am trying to replicate the flow of the 'withCredentials' plugin of Jenkins:
withCredentials([usernamePassword(credentialsId: 'Github_Credentials', passwordVariable: 'TOKEN', usernameVariable: 'USERNAME')]) {
sh "git clone https://$USERNAME:$TOKEN@${repository}"
// do stuffs
}
How can I write a function that can handle the return values/variables as arguments of the function itself?
My function is something like this:
def call(Map config, Closure body) {
def secret_id = config.get("secret_id").toString()
def type = config.get("type").toString()
// do stuffs
body()
}
Is this possible?