This example also shows how to pass parameters from Hudson to Groovy, actually the variable number of parallel tasks is the reason to define them in the groovy script, rather than just using the tag
<parallel>
inside Ant script.In my example all files located in the directory C:\Hudson\
Here is the Ant build file called PropTest.xml :
and the Groovy file PropTest.groovy launching the Ant is this:
def argMap = ["hosts":""]
for (arg in this.args) {
splitArg = arg.split("=")
argMap[splitArg[0]]=splitArg[1].split(",")
}
def ant = new AntBuilder()
ant.parallel()
{
for(host in argMap["hosts"]) {
ant.ant(antfile:"C:\\Hudson\\PropTest.xml", target:"CustomScenario") {
ant.property(name:"host", value:host)
}
}
}
Ant
parallel
task is invoked from Hudson. Just as expected.Also note that this script parses the parameters that came from Hudson through mechanism used by Java to pass in Command-line parameters to a program.
The Hudson job settings for the build step are these:

And finally here is the console output for this Hudson job.
Started by user anonymous
[workspace] $ "C:\Program Files (x86)\Groovy\Groovy-1.7.5\bin\groovy.exe" C:\Hudson\PropTest.groovy hosts="ams-w2k8moss,ams-w2k8sp2010"
CustomScenario:
[echo] CustomScenario started on ams-w2k8moss
CustomScenario:
[echo] CustomScenario started on ams-w2k8sp2010
[echo] CustomScenario finished on ams-w2k8moss
[echo] CustomScenario finished on ams-w2k8sp2010
Finished: SUCCESS
No comments:
Post a Comment