简体   繁体   中英

How can I schedule a Jenkins job to be started only when it is not already running?

The cron part is easy and covered elsewhere. What I have is a job that runs mostly for six hours but sometimes only two or three. If I schedule the job for every six hours and it only runs for two, I waste four hours waiting for the next one. If I schedule it every hour, then when it runs six hours, five jobs are going to stack up waiting their turn.

Rigging something in the job itself to figure out if it already running is sub optimal. There are four machines involved so I can't examine process tables. I would need a semaphore on disk or in some other shared resource, which involves making sure it is cleared not only when the job finishes, but when it dies.

I could also query Jenkins to see if a job is already running, but that's also more code I need to write and get right.

Is there a way to tell Jenkins directly: Schedule only if you are not already running?

Maybe disableConcurrentBuilds could help? https://www.jenkins.io/doc/book/pipeline/syntax/ And you can also clean the queue if needed

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM