2

I'm trying to use Jenkins to run a small monitoring script every minute on two separate ECS clusters. In the text box that opens when you enable "Build periodically with parameters" I wrote:

* * * * * %CLUSTER=Cluster1;

* * * * * %CLUSTER=Cluster2;

This works fine for Cluster1 but it does not run for Cluster2. It does not fail, it just doesn't run. If you switch the lines it works for Cluster2 (which is now at the top) but not for Cluster1. I made sure the node it runs on has enough runners, and that "Execute concurrent builds if necessary" is enabled. The closest thing I found while googling is this, and I checked but there is a blank line after these and adding another or removing it or adding a space between them does not help.

I have a bad workaround which is just squeezing both runs in an unparametrized build and that works but it is inflexible.

So to reiterate the question, why does Jenkins not run concurrent builds from cron, and what can I do to change that?

Thanks.

EDIT:

When you insert a cron schedule of * * * * *, Jenkins posts the following:

Do you really mean "every minute" when you say "* * * * *"? Perhaps you meant "H * * * *" to poll once per hour.

As I need it to be on a per minute basis this is (for the 1st one, but not for the 2nd) the desired result. Based on Ian W's suggestion to do replace the schedule from "* * * * * " to "H/2 * * * *". I checked it but this still led to only the 1st one being run, and would have caused it to run every other minute and not every minute as intended. H/1 doesn't run at all, and H/0.5 returns an error of

Invalid input: "H/0.5 * * * * %CLUSTER=Cluster1;": line 2:3: step must be positive, but found 0

I also tried H/1.1 but that returned:

Invalid input: "H/1.1 * * * * %CLUSTER=Cluster1;": line 2:4: unexpected char: '.'

The closest I got so far was staggering the cron jobs like so:

H/2 * * * * %CLUSTER=Cluster1;

* * * * * %CLUSTER=Cluster2;

Which caused both jobs to run every 2 minutes.

BTW, the Jenkins version is 2.204.1, the Parametrized Scheduler plugin is on version 0.8, if any other plugins are relevant I can post their versions as well.

11
  • This doesn't seem like a use case that Jenkins is intended for... Is there a reason you aren't running the cron jobs on the clusters themselves, or from a container that you deploy in a separate cluster? Or better yet, use a service like AWS Lambda to periodically execute your script every minute.
    – Preston Martin
    Commented Jun 25, 2020 at 5:01
  • @PrestonM, it's better for this task than just a cron job on some server because it's centralized and everyone will know where to look, but mostly it's because of an organizational thing. The QA dept. here know how to work with Jenkins but claim they are too busy to be instructed on proper use of AWS (or ELK, or...). As I need it to be accessible to them I put it where they know to look.
    – Uberhumus
    Commented Jun 25, 2020 at 8:38
  • There is a known issue attemptimg to to every minute, see JENKINS-22129. H/2 will run every 2 minutes, but H/1 will run every hour.
    – Ian W
    Commented Jun 26, 2020 at 7:42
  • @IanW That's true, but doing * * * * *, runs every minute. That bug is unrelated.
    – Uberhumus
    Commented Jun 26, 2020 at 7:45
  • OK, so you can't have two lines (with parameters) that run at the same time as it only takes the first one. You can't use H/1 as there no random interval in minute increments. Tje leaves you stuck. So, make 2 jobs, with * * * * *, and a hard-coded env.
    – Ian W
    Commented Jun 26, 2020 at 7:51

1 Answer 1

2

I believe your issue is the use of * * * * *.

The parameterized-scheduler-plugin example has two different times specified.

#lets run against the integration environment at 15 past the hour
15 * * * * % env=int
#run QA too
30 * * * % env=qa

So one job runs @15 and one @30.

Yours specify the same time, so only the first is executed.

You could try the random time parameter "H" or fix some different interval on each.

Or, it does say "Leave a space. Put in a %. Then add the name=value pairs". So maybe it's cronexp space percent space name=value ?

OR you could just copy the job job and schedule two separate jobs w/fixed parameter. But Jenkins does sound like the wrong tool for this.

The above will address why only the 1st line was executed.

NOTE :There is a known issue attemptimg to to every minute, see JENKINS-22129 H/2 will run every 2 minutes, but H/1 will run every hour.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.