Run Groovy script only on Matrix parent

284 views
Skip to first unread message

Sverre Moe

unread,
Mar 18, 2015, 7:24:23 AM3/18/15
to jenkin...@googlegroups.com
The groovy script executed by Groovy Postbuild does not run on Matrix parent if this Post build publisher comes from a template project.

I order for the script to run on my several hundred jobs I would have to duplicate this script under each job. Maintenance would be a nightmare.

Thankfully Execute System Groovy script could load the script from a file, thus I solve my script duplication problem. It exposes some of the same variables as Groovy Postbuild, such as the current build. However I cannot get the script to run only on Matrix parent

Build -> Execute System Groovy script -> Script command
import hudson.matrix.MatrixBuild;
import hudson.matrix.MatrixRun;

if (build instanceof MatrixRun) {
  println
"MatrixRun child"
} else if (build instanceof MatrixBuild) {
  println
"MatrixBuild parent"
}
It seems it only runs on each matrix build configurations (childs).

Sverre Moe

unread,
Mar 18, 2015, 8:49:56 AM3/18/15
to jenkin...@googlegroups.com
I came by an immediate fix:

Using this Groovy Postbuild script on all my jobs
import hudson.matrix.MatrixBuild;
import hudson.matrix.MatrixRun;

if (manager.buildIsA(MatrixBuild.class)) {
    evaluate
(new File("build-downstream-projects.groovy"))
}

A little bit duplication, but the main logic remains in the groovy script file.

Reply all
Reply to author
Forward
0 new messages