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
0
votes
This is exactly the purpose of a pipeline. What is exactly your problem then ?
– Arnaud Claudel
@ArnaudClaudel i do understand that. But when i have say 10 - 20 jobs, i cannot go run all jobs manually. So this saves lot of time. Please note this is still running the jobs individually by aggregating them.
– user11881
I mean, pipeline are meant for this kind of problem. So I don't understand your question as the solution simply use a normal pipeline.
– Arnaud Claudel
1 Answers
2
votes
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.