Reputation: 65
I have already configured multiple jobs in my Jenkins. For example: let say i have A,B and C jobs configured in my Jenkins. Now i have to run these three jobs manually every time. I want to run a single job which run all these three jobs (A,B,C). Is there a way to achieve this in pipeline job? please advise
Upvotes: 1
Views: 1376
Reputation: 1020
Yes you can run all three jobs within a single pipeline. Here a short pipeline example we use so the user can choose which sub-job should run (default all checkboxes are checked):
node {
properties([
buildDiscarder(
logRotator(
artifactDaysToKeepStr: '',
artifactNumToKeepStr: '10',
daysToKeepStr: '',
numToKeepStr: '10')
),
parameters([
booleanParam(defaultValue: true,
description: 'Select true to include run of Job A',
name: 'JOBA'),
booleanParam(defaultValue: true,
description: 'Select true to include run of Job B.',
name: 'JOBB'),
booleanParam(defaultValue: true,
description: 'Select true to include run of Job C',
name: 'JOBC')
])
])
try {
if (params.JOBA == true) {
stage('Run job A') {
build job: 'PATHTOJOBA', propagate: true, wait: true
}
}
if (params.JOBB == true) {
stage('Run job B') {
build job: 'PATHTOJOBB', propagate: true, wait: true
}
}
if (params.JOBC == true) {
stage('Run job C') {
build job: 'PATHTOJOBC', propagate: true, wait: true
}
}
--------
The PATHTOJOB
is the fullname of the job you want to run. Generate a script using <yourJenkinsHost>/pipeline-syntax/
and use Sample step
> build: Build a job
to identify if your path to your job is correct + it generates parameters which can be passed to that job if that is configured.
Read more documentation here. If all three jobs can run independently it's advised to run your jobs in parallel to save time.
Upvotes: 2