dildeepak dildeepak - 3 months ago 44
Groovy Question

How to set the JDK version for the jenkins job

We have a requirement that we need to set the JDK version to 1.8 from 1.7 for all the jobs ran during last 3 months.

import hudson.model.*
import hudson.task.*

for (item in Hudson.instance.allItems){
if(item.JDK != null){
manager.listener.logger.println("test job are : " + item.name);
manager.listener.logger.println("JDK : " + item.JDK);
manager.listener.logger.println("\n =========== \n");

With the above code, i am able to fethc the JDK version for all the Test jobs, in the below format.

test job are : jacoco_test
test job are :kps-batch-snapshot-test

but i am not able to set them to IBM-JDK-8.

Thanks in Advance..


According to the Javadoc, it can be done using setJDK(). Try this:

item.JDK = Jenkins.instance.getJDK('IBM-JDK-8')