How to trigger a job at a certain time in Jenkins pipeline?

20 views
Skip to first unread message

zil...@gmail.com

unread,
Sep 15, 2020, 10:40:20 AM9/15/20
to Jenkins Users
I see this, but I don't understand how to implement it for my use case.

I want JobA to trigger JobB, but at a certain time. I do this now

Step in JobA to trigger JobB
build job: JobB,
      wait: true

...but I wish I can do this (for illustration only, the cron option does not exist of course)

Step in JobA to trigger JobB to run around 9:00pm ET
build job: JobB,
      cron: "H 21 * * 1",
      wait: true

Any ideas? Thanks!

Gianluca

unread,
Sep 15, 2020, 10:47:34 AM9/15/20
to Jenkins Users
From what I know that's specific thing is not possible.
And to be honest, it's quite strange as well.

Maybe if you explain us why are you trying to do that, we could suggest alternatives that are possible in Jenkins.

Cheers,
Gianluca.

Fabian Cenedese

unread,
Sep 15, 2020, 10:56:48 AM9/15/20
to Jenkins Users

>...but I wish I can do this (for illustration only, the cron option does not exist of course)
>
>Step in JobA to trigger JobB to run around 9:00pm ET
>build job: JobB,
> cron: "H 21 * * 1",
> wait: true

How about JobB always runs at 9 (started from cron)
and always checks first, whether it should be executed
or not. JobA would set a "flag" or variable or whatever
to let JobB know that it should go on, once it's been
started.

bye Fabi

zil...@gmail.com

unread,
Sep 15, 2020, 11:05:46 AM9/15/20
to Jenkins Users
Thanks for responding Gianluca.

So I have a Jenkins job that builds production code mid-day, but does NOT deploy it. We have a a separate deployment job that's cron'ed at "H 21 * * 1" to deploy the code built by the mid-day build job

Part of the mid-day build is to check if certain microservices' versions need to be deployed to production as well, and I'd like for it to trigger a job for each microservice it needs to deploy at "H/30 20 * * 1". IOW the needed microservices can not be deployed mid-day either.

Hope that explains it.

zil...@gmail.com

unread,
Sep 15, 2020, 11:07:18 AM9/15/20
to Jenkins Users
Hi Fabi,

Great idea. How can JobA set a flag for JobB that persists when JobB runs at 9:00pm ET?

zil...@gmail.com

unread,
Sep 15, 2020, 11:26:16 AM9/15/20
to Jenkins Users

Fabian Cenedese

unread,
Sep 15, 2020, 11:26:18 AM9/15/20
to Jenkins Users
At 17:07 15.09.2020, zil...@gmail.com wrote:

>Hi Fabi,
>
>Great idea. How can JobA set a flag for JobB that persists when JobB runs at 9:00pm ET?

That depends on your system. I don't know if there's a Jenkins internal
way to do this. But if the jobs run on the same machine then maybe
you could set an environment variable, or create a file at a specific
location. Maybe leave a file on a network share. Use anything that
will persist and is accessible from both jobs.

bye Fabi

Gianluca

unread,
Sep 15, 2020, 11:26:48 AM9/15/20
to Jenkins Users
Yes, it explains.

I would suggest to use intermediate artifacts / published files to use on the "Deploy" job to know what to do instead of trigger that from "Build" job.
(I'm calling "Build" the one that runs on mid-day and "Deploy" the one that runs at "H 21 * * 1")

So, in my suggestion the flow would be that "Deploy" job will be triggered by Jenkins base on "cron" trigger and when it runs, it will checks if there is a list of thing to deploy produced by "Build" job.
You can do the latter in many ways. One that's part of the Jenkins core is archiveArtifacts: https://www.jenkins.io/doc/pipeline/steps/core/
So, "Build" job will archive, let's say a JSON listing all microservices that need to be deployed. Then "Deploy" job will look for that list and if it's not empty, it will deploy all those listed microservices.

I hope that helps.

Cheers,
Gianluca.

zil...@gmail.com

unread,
Sep 15, 2020, 11:40:18 AM9/15/20
to Jenkins Users
Gianluca,

Perfect. I'll look into this.

Thanks,
Chris

Reply all
Reply to author
Forward
0 new messages