Home > Enterprise >  Executing multiple jenkins jobs
Executing multiple jenkins jobs

Time:08-29

Can someone please let me know how i can trigger multiple Jenkins jobs? We have 5-6 jobs that we need to trigger manually post some technical upgrades. We are having to navigate to these jobs manually and click on 'Build'. Is there anyway i can create a new job or shell script that will help me in triggering all of these jobs with a single click/run.

CodePudding user response:

Simplest approach will be creating a new pipeline which will trigger other pipelines. You can also make stages parallel to faster execution if order is not issue. You can find detailed answer and approach here

CodePudding user response:

Yes, you can do it in both ways that you mentioned. Creating a new job that will run all these other jobs as downstream jobs is the fastest and easiest.

To do this, create a new job, and if you are using declarative Jenkins, then specify the jobs to be triggered:

stage ('trigger-multiple-jobs') {
    parallel {
        stage ('first job') {
            steps {
                build([
                    job       : 'JobName',
                    wait      : false,
                    parameters: [
                        string(name: 'PARAM_1', value: "${PARAM_1}")
                    ]
                ])
            }
        }
        stage ('second job') {
            steps {
                build([
                    job       : 'JobName2',
                    wait      : false
                ])
            }
        }
    }
}

You can alternatively create a freestyle job, navigate down to the Trigger downstream jobs section, and set the jobs you want to be triggered from the drop down.

If you want to use a shell script, then you can trigger the jobs using API calls. This is described well in this answer.

  • Related