??????????
????????? Automation ????????????10???????????????????????????????
??????????Jenkins?????????У????????1-10?????????????????????????????Jenkins??????????master/slave ???????£?
????Dispatcher Job:
????1?? ??????????????????????????????????:
????- Choice Parameter: slave Node ?????????????NodeLabel1???????????????

????- File Parameter: ?????????????????

????2?? ??Build Steps??trigger seed job:

????Seed Job: ???t???????н????
????????????????
???????к????????????????????
???????Slave Node????????Choice Paramter ?? File Parameter??
????Build Step???????10??trigger seed job??
????Steps?????????????????????????10??
???????????????????????????Parameters??????????Node?? ??Steps????????
???????????
??????????????Node?б???????????????????Node??
??????Build Steps?У???????trigger seed job?????????????????10??trigger step?? ?????????(Reusability)??
?????????????
???????Groovy????????Jenkins?????
????Active Choices : ???????????????????????Groovy??????????????Scriptlet???????
????Scriptler ??Groovy??????????????й??????????
????Job-DSL : ???????????DSL???ú?????Job??????
????????????
???????global scripts????????????????scriptler?????
????1?? ??Jenkins->Scriptler?д???getAllNodeByProject.groovy???????????????е?Node?????????????????????Щ???????????????????
????scriptler??????????????????project???????????????????job????y??????????á?
def list = jenkins.model.Jenkins.instance.slaves.findAll{
if (it.name.contains(project)) it.name
}.collect{it.name}
list.add(0??"None")
return list

????2?? ??Jenkins->Scriptler?д???getRuntimeNodes.groovy????????????dispatcher job????????????Node??????
import hudson.model.*
def list =""
def runable=false
def build = Thread.currentThread()?.executable
// get the selected node parameter value at runtime
def nodes = build?.actions.find { it instanceof ParametersAction }?.parameters.collect{
(it instanceof StringParameterValue)?it.value:""
} as List
println "node is $nodes"
nodes.unique().removeAll(["None"])
nodes.remove(" ")
nodes.remove("")
if (nodes!=[]) {
list=nodes.join("??").toString()
}
println "list is:  $list"
if (list!=" " && list!="") runable=true
println "runable is $runable"
build.addAction( new ParametersAction([new StringParameterValue("runtimeNodes"??list)]))
build.addAction( new ParametersAction([new BooleanParameterValue("runable"??runable)]))
???????н???????dispatcher job runtime???????????????
????String???? runtimeNodes: ???????????????????Node ?????б?????????????Щnode ????????trigger seed job
????????????? runable????????????κ?Node????runable???false?? ??????trigger seed job
????????main??dispatcher??seed jobs
?????????????????main?? job?? ???????????dispatcher and seed jobs.
??????main????job-dsl????dispatcher job
??????main job?У????????Process Job DSLs ???????裬 ????????????????????????????dispatcher??job:
????????language node ??“Client_CHS"??"Client_JPN") ??????active choice node ??????File??????
???????????conditional step?? ???????????????trigger seed job???????????????????????node??NodeListFactory???????????seed job??
import hudson.model.*
// get all available nodes if its name contains "client" - specific for our project use;
def nodes = hudson.model.Hudson.instance.slaves.findAll{
if (it.name.contains("Client")) it.name
}.collect{it.name}
nodes.add(0??"None")
//def nodes = ["Client_JPN"??"Client_CHS"]
defineJob(nodes-["None"]??"dispatcher") // setup the dispatcher job
// method to define a dispatcher job
def defineJob(nodes??jobName) {
return job(jobName) {
def list =[]
nodes.each {
def node =it
parameters {
activeChoiceParam(node) {
description('Allows user choose from choices')
filterable()
choiceType('SINGLE_SELECT')
scriptlerScript('getAllNodesByProject.groovy') {
parameter('project'?? 'Client')
}
}
fileParam(node+'_File'?? 'Select test case file to upload')
}
}
steps {
//systemGroovyScriptFile('${JENKINS_HOME}\scriptler\scripts\getRuntimeNodes.groovy') {
systemGroovyCommand(readFileFromWorkspace("${JENKINS_HOME}\scriptler\scripts\getRuntimeNodes.groovy")){
}
conditionalSteps {
condition {
booleanCondition("${runable}")
}
steps{ downstreamParameterized {
trigger('seed') {
/* parameters{
println node
nodeLabelBuildParameter {
name(node)
nodeLabel(node)
}*/
parameterFactories {
nodeListBuildParameterFactory {
// The name of the parameter to set.
name("test")
// A comma separated list of nodes to execute the job on.
nodeListString("${runtimeNodes}")
}
//booleanParam("f"??true) /
}
}
}
}
}
}
}
}
???????????? main job???????????? dispatcher job ?? seed job ??????