| Did anyone ever get this to work with the `configure` block? I lost a day of my life trying to modify the job xml in a `configure` block to enable the sandbox. Finally I got it so far:
pipelineJob("foo") {
parameters {
activeChoiceParam('Param') {
choiceType('SINGLE_SELECT')
groovyScript {
script('return ["a","b","c"]')
}
}
}
// we need to wrap the active choice parameters' groovy script and fallbackScript
// inside a secureScript wrapper with the sandbox enabled
configure { proj ->
// find all <script class="...GroovyScript"> nodes via depth-first search
def scriptContainers = proj.'**'.findAll{ n ->
n.class == Node && n.'@class' == 'org.biouno.unochoice.model.GroovyScript'
}
scriptContainers.each { s ->
// wrap <script> inside a <secureScript>
s.appendNode('secureScript', [plugin: 'script-...@1.25']).with {
appendNode('script', s.script.value)
appendNode('sandbox', 'true')
parent.remove(s.script)
}
}
}
}
It seems to work (i.e. XML looks ok) on https://job-dsl.herokuapp.com/, but when used in Jenkins it still does not work. The generated config.xml ends up with both <script> and <secureScript> tags side-by-side, i.e. the removal of the script element via {{ parent.remove(s.script) }} does not work when this JobDSL runs in Jenkins. I had tried a variation with {{ replaceNode }} but this would not work in https://job-dsl.herokuapp.com ("java.lang.UnsupportedOperationException: Replacing the root node is not supported"). It did not throw this exception when run in Jenkins, but also not make any difference – still both elements there and the script needs approval. Help?! |