Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ansig/07cde06a90516f111729d085af229131 to your computer and use it in GitHub Desktop.
Save ansig/07cde06a90516f111729d085af229131 to your computer and use it in GitHub Desktop.
JobDSL: add secure Groovy script in sandbox with configure blocks
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