Create new property file
- Create new property file namely as “test_prop.properties” and stored in any location. Here I have stored in “D:” drive
- Property file location: “D:\test\test_prop.properties”
- Property file has key=value pair concept. Here “keys” are our Test module names, “Values” are related Test case names for that module.
Read Keys (Test Module Name) from property file
- Go to Jenkins job configure page
- Select “This build is parameterized” plugin
- Select “Active choice parameter”
- Give Name = Test_Module and select “Groovy Script” option
- Copy below groovy code into that groovy script text area
- Change property file location based on your drive (if it is Linux, change accordingly)
- Select choice type like how to appear in Jenkins UI like whether Check-box/single-select/multi-select….
Groovy Code:
//START
println “Starting Test_Module Script !!!”
//define property object//
def props = new Properties()
//initialize property file path//
def stream = new FileInputStream(“D:/test/test_prop.properties”)
try {
//load property file//
props.load(stream)
} finally {
//once loaded close the stream//
stream.close()
}
//get only property keys and convert into string array//
def parameters=props.keySet() as String[];
//for sorting
parameters= parameters.sort { it.size() }
//def values = parameters.split(‘,’)//
//convert string array into list
def var = Arrays.asList(parameters)
//just print list
System.out.println(var)
//return list to dropDown
return var
//END
- Finally save the configuration page
- Verify saved script in Jenkins UI by clicking “Build with Parameters”
Hi Sathish,
Is there any option to use “Groovy Script” as variable for “active choices reactive parameter”.
We are using one commong “Groovy Script” in a set of jenkins jobs. IS ther option to set this script like “Environment Variable” .?
LikeLike
HI Vimal,
Have you tried to pass Groovy script file instead property file?
LikeLike