Reputation: 887
I have two Jenkins jobs and I need to run them in parallel but with a gap of 1 or 2 mins. I mean, once 'Job1' starts then after a gap of 1 minute, 'Job2' should start. 'Job1' takes approximately 6-7 mins to get over. I am able to run the jobs parallely but I am not able to put a gap of a minute or two between them. Here is my code:
node('LINUX_TEST_BOX'){
parallel 'Parallel_1': {
node('LINUX_TEST_BOX') {
stage 'P1'
build 'Job1'
}
},
'Parallel_2': {
node('LINUX_TEST_BOX') {
stage 'P2'
build 'Job2'
}
}
}
The above code runs fine. How do I make Job2 to run after 2 mins, once Job1 starts? There are totally two things I am looking for.
Thank you!
Upvotes: 0
Views: 3680
Reputation: 1509
If they need to run on the same machine and don't require isolation, you might not need the multiple node calls. Parallel doesn't explicitly require that, so you can reduce it to just...
node('LINUX_TEST_BOX'){
parallel 'Parallel_1': {
stage 'P1'
build 'Job1'
},
'Parallel_2': {
stage 'P2'
build 'Job2'
}
}
}
Alternatively, there is an environment variable called NODE_NAME that you can pass into the node function in the parallel sections that should work.
node('LINUX_TEST_BOX'){
parallel 'Parallel_1': {
node(env.NODE_NAME) {
stage 'P1'
build 'Job1'
}
},
'Parallel_2': {
node(env.NODE_NAME) {
stage 'P2'
build 'Job2'
}
}
}
To get a list of other env vars, go to /pipeline-syntax/globals#env. There is one to get the labels of your node as well.
Upvotes: 1