Trigger secondjob after some delay of first job execution

34 views
Skip to first unread message

Hemanth Reddy

unread,
Mar 14, 2017, 5:20:41 AM3/14/17
to Jenkins Users
Hi All,

I have a requirement some thing like, my first job will run test cases on the machine.

I need to configure another job in such a way that after 1 hour of first job triggered, my second job should run to collect the logs.

Regards,
Hemanth

Bill Dennis

unread,
Mar 15, 2017, 7:25:44 PM3/15/17
to Jenkins Users
Hi -

You can do it with a declarative pipeline job to orchestrate running your test and log collection jobs.

Something like this using 'agent none' so you don't tie up executors when waiting at any point:

pipeline {
    agent none
   
    stages
{
        stage
('Build') {
            steps
{
                echo
'Triggering test cases..'
               
build job: 'TestIt', wait: false
            }
       
}
       
        stage
('Waiting for something') {
            steps
{
                echo
'Waiting to collect logs'
                sleep time
: 1, unit: 'MINUTES'
           
}
       
}
       
        stage
('Collect Logs') {
            steps
{
                echo
'Collecting the logs'
                build
'CollectLogs'
           
}
       
}
   
}
   
    post
{
        success
{
            echo
"All done"
       
}
       
        failure
{
            echo
"Something failed"
       
}
   
}
}

But how will you know the 1 hour wait is enough? If you trigger the test cases job but elect to wait for that job to complete, will the logs be ready to collect? Like this which defaults to waiting:

build 'TestIt'

--Bill

Bill Dennis

unread,
Mar 15, 2017, 7:28:04 PM3/15/17
to Jenkins Users
Should have been:

sleep time: 1, unit: 'HOURS'

Hemanth Reddy

unread,
Mar 16, 2017, 10:00:52 PM3/16/17
to Jenkins Users
Thanks Bill,

If my First job runs for 10 hours,
My second job needs to be run for every 1 hour to just collect the logs. Means second job should be triggered 10 times.

Reply all
Reply to author
Forward
0 new messages