2

I've got a Jenkins job hierarchy looking something like this:

Collection/
    ParentJob
    Children/
        Foo
        Bar
        Baz

ParentJob has a few different configurations and the jobs in Children/ need to be built for each of those configurations. These configurations are basically just checking out different branches and building those branches. Additionally, part of each configuration of ParentJob has to be completed before the child jobs can run.

How can I trigger all the jobs in Children after the necessary parts of each ParentJob configuration are finished?

My first thought was to just put a build 'Children/*' step in ParentJob's pipeline, but it seems Jenkins does not support wildcards in that context.

I could explicitly list all the jobs, but that would be tedious (there's several dozen child jobs) and prone to breakage as child jobs may be added or removed.

Ideally a solution would allow me to just set up a new child job without touching anything else and have it automatically triggered the next time ParentJob runs.

Community
  • 1
  • 1
8bittree
  • 1,769
  • 2
  • 18
  • 25
  • My answer here https://stackoverflow.com/questions/46834998/scripted-jenkinsfile-parallel-stage/53456430#53456430 may help. – Ed Randall Jul 23 '19 at 18:21

2 Answers2

3

You could get a list of the child jobs and use a for loop to build them. I haven't tested this, but I see no reason why it would not work.

I structure my job folders in a similar fashion to take advantage of naming conventions and for role-based security.

import jenkins.model.*

def childJobNames = Jenkins.instance.getJobNames().findAll { it.contains("Collection/Children") }

for (def childJobName : childJobsNames)
{
    build job: childJobName, parameters: [
        string(name: 'Computer', value: manager.ComputerName)
    ],
    wait: false
}

http://javadoc.jenkins.io/index.html?hudson/model/Hudson.html

Dan Wilson
  • 3,937
  • 2
  • 17
  • 27
0

You need to use the Jenkins Workflow or Pipeline, and then you can run a stage, then some in parallel, and then a sequential set of stages, etc. This StackOverflow Question and Answer seems to be a good reference.

Steven Scott
  • 10,234
  • 9
  • 69
  • 117
  • I'm not sure about that. Seems like that would require me to explicitly list out all the child jobs in ParentJob. – 8bittree Oct 18 '17 at 18:37
  • Yes, I guess @8bittree already uses Jenkins Pipelines.. so this answer makes little sense to me. – StephenKing Oct 18 '17 at 19:05
  • The Pipeline would force you to list everything in the script, but does give you the stacked control (parallel, sequential) at different stages if you need it. – Steven Scott Oct 18 '17 at 22:37