10

Will this expression run the build every other Friday at noon? Assume i set this up on a Friday?

0 12 * * */14

I tried 0 12 * * FRI/14 but Jenkins returned an error.

I ma trying to run a code report job every two weeks to match scrum.

Eric Hanzl
  • 119
  • 1
  • 1
  • 5
  • 2
    I don't think that will work, because the numbers in `[0-7]` (the days of the week) are never divisible by 14, so it'll just never fire. – danehammer Nov 18 '15 at 18:53

5 Answers5

9

You'll have to add some logic to the build script to determine if it ran last week, and then run it every week.

I looked around similar questions for cron jobs, and you have to do some shell magic to make it work.

You could try what was suggested here:

H H 8-14,22-28 * 5

Which would qualify on Fridays that are in the second or fourth week of the month.

danehammer
  • 416
  • 3
  • 13
  • 2
    it would be preferrable to edit your answer directly to the answer instead of link (it is good to keep the link as a reference though) – eis Nov 18 '15 at 18:59
  • 1
    H H 1-14,22-28 * 5 how about 1-14 instead of 8-14, so that the run can be more evenly distributed – 3lokh Dec 21 '17 at 09:27
5

it will run at noon every other friday 00 12 */2 * 5

Siva
  • 113
  • 4
  • 13
  • 1
    Not perfect. It will run every Friday that is at an odd date. This April 2022 has 3 odd Fridays, for example, which means it will run two consecutive weeks (5th April firday, 1st May friday). Every year has 4 or 5 such months. – Lubo Kanev Jan 17 '22 at 06:35
4

I had the same issue, the easy work around I found was to create another job that run weekly.
This job was a simple groovy script that does the following:

import jenkins.model.*;
def job = Jenkins.instance.getJob('JobNameToRunEveryTwoWeek')
job.setDisabled(!job.isDisabled())

Since Jenkins does not offer the functionnality its the best easy solution I could find. If you have better solution feel free to let me know.

wincrasher
  • 121
  • 1
  • 10
3

One ridiculous-looking-but-it-works answer: schedule your job to run every week, and then at the top of the job add the following:

// Suppressing even number builds, so this job only runs
// every other week.
def build_number = env.BUILD_NUMBER as int
if ((build_number % 2) == 0) {
  echo "Suppressing even number builds!"
  echo """THIS IS A HACK TO MAKE THIS JOB RUN BIWEEKLY.

Jenkins cron scheduling currently doesn't support scheduling a
bi-weekly job.  We could resort to shell or other tricks to
calculate if the job should be run (e.g., comparing to the date
of the last run job), it's annoying, and this works just as well.

Schedule this job to run weekly.  It will exit early every other week.

refs:
* https://stackoverflow.com/questions/33785196/i-want-jenkins-job-to-build-every-two-weeks
* https://issues.jenkins-ci.org/browse/JENKINS-19756
"""
  currentBuild.result = 'SUCCESS'
  return
}
J.Z.
  • 882
  • 9
  • 13
0

For Jenkins, you can try this approach as well.

1 1 8-14,21-28 * 5

Sulaiman
  • 101
  • 1
  • 1
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Apr 22 '22 at 15:11