'I want Jenkins job to build every two weeks

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.



Solution 1:[1]

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.

Solution 2:[2]

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.

Solution 3:[3]

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

Solution 4:[4]

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
}

Solution 5:[5]

For Jenkins, you can try this approach as well.

1 1 8-14,21-28 * 5

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 wincrasher
Solution 3 Siva
Solution 4 J.Z.
Solution 5 Sulaiman