问题
I have two jobs, JobA and JobB, JobA runs every day at 13.00 and registers some payments. I want JobA to trigger JobB which verifies the payments, if and only if JobA is successful and JobB needs to be run the next day at 04.00
Any idea how to do this?
BR
回答1:
I have not been able to find anything that will do this out of the box. You can, of course, schedule a job to build periodically, but that's not all that you want.
You could try one of these 2 ideas (I have not implemented either myself).
- Set JobB to build periodically at 4am, but deactivate the job. Create an intermediary job with a build trigger to build if JobA is successful (e.g. set JobA in the projects to watch section). The intermediary job would run code to activate JobB - groovy code using the groovy plugin would be easiest, or you could use the rest api via shell / batch script. Then as the last build step in JobB, run a similar script to deactivate the job again.
- The Schedule Build Plugin allows you to schedule future builds. However, it appears that this is a manual process. If you can figure out how to programatically fire off a scheduled build through this plugin, you could add that code to an intermediary job that is setup in the same way as mentioned in option #1.
回答2:
You can use build job: step in pipeline (https://jenkins.io/doc/pipeline/steps/pipeline-build-step/) and quite period in seconds to trigger the job at required time.
EDIT:
The way i did def currentDate = GregorianCalendar.getInstance()
If you want next day at 5 am def plannedDate = new GregorianCalendar(currentDate.get(Calendar.YEAR), currentDate.get(Calendar.MONTH), currentDate.get(Calendar.DAY_OF_MONTH) + 1, 5, 0)
def quietPeriod = (plannedDate.getTime().getTime() - currentDate.getTime().getTime())/1000
来源:https://stackoverflow.com/questions/37003317/how-to-trigger-a-jenkins-job-by-another-job-at-a-certain-time