How to trigger multiple jobs programmatically in Jenkins

I need to trigger all the jobs in a specific view programmatically and connect it to a Spring Boot controller class. The jobs are in my local Jenkins.

I read the links, but it can only trigger one job at a time. I have like 50 jobs in my Jenkins. how do I trigger all at once.

I cannot edit all the jobs from the job config and then execute it, so I need another way, maybe from Jenkins CLI, but I don’t know how to do that.

Answer

You can use groovy and scheduleBuild2. This to trigger the build – waitPeriod 0

This should work…

Jenkins.instance.getView('<VIEW>').items.each() {
    it.scheduleBuild2(0)
}

Leave a Reply

Your email address will not be published. Required fields are marked *