I am creating a jenkins thread using an assembly thread plugin that will capture all jobs, compare the name with the regular expression, and if it matches it, it will call the job assembly.
This works fine for me:
import jenkins.model.Jenkins import java.util.regex.* Pattern myRegex = ~/release_status.*/ for (item in jenkins.model.Jenkins.instance.items) { if (item.name ==~ myRegex) { build( "$item.name" ) } }
However, it takes a lot of time to create all the suitable tasks (now there are 20, but there can be many).
I try to make it run every work in parallel, but I cannot understand the groovy syntax.
I tried 3 different ways:
import jenkins.model.Jenkins import java.util.regex.* Pattern myRegex = ~/release_status.*/ parallel ( { for (item in jenkins.model.Jenkins.instance.items) { if (item.name ==~ myRegex) { build( "$item.name" ) } } } )
^^ This still works, but works the same as before. He follows one task at a time and does not build the next until the previous one is completed.
import jenkins.model.Jenkins import java.util.regex.* Pattern myRegex = ~/release_status.*/ parallel ( { for (item in jenkins.model.Jenkins.instance.items) { if (item.name ==~ myRegex) { { build( "$item.name" ) }, } } } )
^^ These are errors with
Script1.groovy: 9: Ambiguous expression could be either a parameterless closure expression or an isolated open code block; solution: Add an explicit closure parameter list, eg {it -> ...}, or force it to be treated as an open block by giving it a label, eg L:{...} @ line 9, column 9. { build( "$item.name" ) },
the gap
import jenkins.model.Jenkins import java.util.regex.* Pattern myRegex = ~/release_status.*/ parallel ( [ for (item in jenkins.model.Jenkins.instance.items) { if (item.name ==~ myRegex) { useless: { build( "$item.name" ) }, } } ] )
the gap
import jenkins.model.Jenkins import java.util.regex.* Pattern myRegex = ~/release_status.*/ parallel ( for (item in jenkins.model.Jenkins.instance.items) { if (item.name ==~ myRegex) { { build( "$item.name" ) }, } } )
Both of the blocks above error with the following:
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: Script1.groovy: 5: unexpected token: for @ line 5, column 5. for (item in jenkins.model.Jenkins.instance.items)
There is a lot of code here, but its pretty simple. Looking around, I cannot find many good resources on groovy.