Last active
May 25, 2022 12:00
-
-
Save turboBasic/29d91fcc13307ad3adeaae3bae9d1cae to your computer and use it in GitHub Desktop.
Dynamically change caller of Groovy closure #groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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