Created
August 21, 2017 09:11
-
-
Save ansig/07cde06a90516f111729d085af229131 to your computer and use it in GitHub Desktop.
JobDSL: add secure Groovy script in sandbox with configure blocks
This file contains hidden or 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
Closure envVar(String key, String val) { | |
return { | |
it / 'buildWrappers' / 'EnvInjectBuildWrapper' / 'info' << { | |
propertiesContent("${key}=${val}") | |
} | |
} | |
} | |
Closure secureGroovyScript(String scriptText, boolean useSandbox) { | |
return { | |
it / 'buildWrappers' / 'EnvInjectBuildWrapper' / 'info' << { | |
'secureGroovyScript' { | |
script(scriptText) | |
sandbox(useSandbox) | |
} | |
} | |
} | |
} | |
freeStyleJob('my-job') { | |
wrappers { | |
configure secureGroovyScript('println "Hello world!"', true) | |
// need to use configure blocks to add more variables to the same | |
// configuration, unsure if there is any other way | |
configure envVar('BAZ', 'qux') | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment