Reputation: 314
I need to run 5 Jenkins build
starting from midnight. For each build
execution time may be different.
Currently, I'm scheduling the builds periodically in the pipeline.
Schedule: 0 0,2,4,6,8 * 10 *
each build takes up to 1:15 hrs some may take less than an hour if some failures occur. I need to run builds
after the previous build
is completed. How can I achieve this?
Upvotes: 0
Views: 1310
Reputation: 2076
Below works everytime and is easy too.
pipeline {
agent any
triggers {
cron 'H 0 * * *'
}
stages {
stage('Test') {
steps {
script{
container('tools') {
build job: 'path/to/job1', parameters: [string(name: 'tag', value: '123')]
build job: 'path/to/job2', parameters: [string(name: 'tag', value: '123')]
build job: 'path/to/job3', parameters: [string(name: 'tag', value: '123')]
build job: 'path/to/job4', parameters: [string(name: 'tag', value: '123')]
build job: 'path/to/job5', parameters: [string(name: 'tag', value: '123')]
failFast: true
}
}
}
}
}
}
Cron is set to trigger the job everyday by midnight. Once the above job runs, it starts running all the other jobs sequentially. Use the above snippet for running 5 different jobs sequentially.
If you want to run the same job 5 times, then replace those 5 lines of build jobs above to below.
for (int i = 0; i < 5; ++i) {
build job: 'path/to/the/job', parameters: [string(name: 'tag', value: '123')]
}
Upvotes: 3