Hello,
I need some help. I would like to use the activechoise parameter which is reading dynamicly all installed JDKs.
Does any body have an idea if this is possible or have some small code snipped for me?
Thank you and BR,
Thomas
Hello,
I need some help. I would like to use the activechoise parameter which is reading dynamicly all installed JDKs.
Does any body have an idea if this is possible or have some small code snipped for me?
Thank you and BR,
Thomas
Hello @drexlert and welcome to this community
Are you sure you need the Active Choice plugin to choose a JDK installation?
What kind of project do you have? FreeStyle, declarative Pipeline, scripted Pipeline?
Hi @poddingue,
maybe you get me wrong
I need inside a pipline job an active choise paramter which provides the information which jdks are availabe on the system to chose one of them and handover this to a JobDSL which greats a new Jenkins Job with this information.
hopefully it is now more clear.
BR
I have found a solution. This can be used from the active choise parameter of the pipeline job to handover the choosen string to a jobdsl.
import jenkins.model.*
def inst = Jenkins.getInstance()
def jdk = inst.getJDKs()
for (int index =0; index < jdk.size; index++){
jdk[index] = jdk[index].toString().replace("JDK ", "")
jdk[index] = jdk[index].toString().replace("]", "")
}
return jdk
Now i would need some simular for maven and nodeJs which are configured in Global Tool Configuration.
Nice job!
Thanks a lot for the feedback
As for Maven, I haven’t seen anything in the Javadoc that gives access to which versions are installed.
I think you could get the list of nodes, and then execute a shell on each node to know which versions are installed.
The only thing i have to add is.
It looks like if you execute this peace of code the UI will be destroid in the Global Tool Configuration section of JDK.
After execution of this code it looks like all JDK Settings are gone, but they are still in the config.xml and after a restart of Jenkins all JDK settings are visible again until you execute the code snippet again
Regarding this problem i changed my solution du parse the config.xml where the set jdks available, too.
import groovy.util.XmlSlurper
def output = new StringWriter()
def error = new StringWriter()
def cmd = 'cat <pathofyourjenkinshome>/config.xml'
def list = [] as List
def catresult = cmd.execute().with{
it.waitForProcessOutput(output, error)
return output
}
def parsedXML = new XmlSlurper().parseText(catresult.toString())
parsedXML.jdks.jdk.findAll { it.name }.each { list.add(it.name.text()) }
return list
For Maven and NodeJS i will follow a simular way with parsing some xml files.