Reputation: 3615
I'm unfamiliar with Groovy syntax, but spent a bit of time researching this. I'm working with a Jenkinsfile, and I have a section that looks like this:
configFileProvider([/* ... */]) {
withCredentials([/* ... */]) {
sh 'my command'
}
}
Does Groovy syntax enable a shorter expression of this same logic? I'm not a fan of the indentation here.
Upvotes: 0
Views: 366
Reputation: 1179
You can assign any closure to a variable and pass it. So you could refactor to:
def shCommand = { withCredentials([...]) {
sh 'my command'
}}
configFileProvider([...], shCommand)
or
def shCommand = {
sh 'my command'
}
configFileProvider([...]) {
withCredentials([...], shCommand)
}
Upvotes: 1