Implemented feedback from @jetersen
Much cleaner solution provided by @jetersen which is also backwards compatible
This commit is contained in:
parent
2c79c128c5
commit
d1aded8ef6
|
|
@ -45,29 +45,15 @@ func (c *configurationAsCode) Ensure(jenkins *v1alpha2.Jenkins) (requeue bool, e
|
||||||
}
|
}
|
||||||
|
|
||||||
const applyConfigurationAsCodeGroovyScriptFmt = `
|
const applyConfigurationAsCodeGroovyScriptFmt = `
|
||||||
import hudson.util.VersionNumber
|
|
||||||
|
|
||||||
String[] configContent = ['''%s''']
|
String[] configContent = ['''%s''']
|
||||||
|
|
||||||
def configSb = new StringBuffer()
|
def configSb = new StringBuffer()
|
||||||
for (int i=0; i<configContent.size(); i++) {
|
for (int i=0; i<configContent.size(); i++) {
|
||||||
configSb << configContent[i]
|
configSb << configContent[i]
|
||||||
}
|
}
|
||||||
|
|
||||||
def stream = new ByteArrayInputStream(configSb.toString().getBytes('UTF-8'))
|
def stream = new ByteArrayInputStream(configSb.toString().getBytes('UTF-8'))
|
||||||
|
def source = io.jenkins.plugins.casc.yaml.YamlSource.of(stream)
|
||||||
def plugin = jenkins.model.Jenkins.instance.getPluginManager().whichPlugin(io.jenkins.plugins.casc.ConfigurationAsCode)
|
|
||||||
def version = plugin.getVersionNumber()
|
|
||||||
|
|
||||||
def source
|
|
||||||
|
|
||||||
switch (version) {
|
|
||||||
case { it.isNewerThanOrEqualTo(new VersionNumber("1.41")) }:
|
|
||||||
source = new io.jenkins.plugins.casc.yaml.YamlSource(stream)
|
|
||||||
break
|
|
||||||
default:
|
|
||||||
source = new io.jenkins.plugins.casc.yaml.YamlSource(stream, io.jenkins.plugins.casc.yaml.YamlSource.READ_FROM_INPUTSTREAM)
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
io.jenkins.plugins.casc.ConfigurationAsCode.get().configureWith(source)
|
io.jenkins.plugins.casc.ConfigurationAsCode.get().configureWith(source)
|
||||||
`
|
`
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue