Skip to content

Instantly share code, notes, and snippets.

@turboBasic
Last active May 25, 2022 12:00
Show Gist options
  • Save turboBasic/29d91fcc13307ad3adeaae3bae9d1cae to your computer and use it in GitHub Desktop.
Save turboBasic/29d91fcc13307ad3adeaae3bae9d1cae to your computer and use it in GitHub Desktop.
Dynamically change caller of Groovy closure #groovy
void withOptionalDocker(String dockerImageName, Closure body) {
(dockerImageName
? { c -> withDockerContainer(image: dockerImageName) {c()} }
: { c -> c() }
)(body)
}
withOptionalDocker(shouldUseDocke() ? 'my-image' : null) {
sh 'doSomething'
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment