Eric Hanzl
Eric Hanzl

Reputation: 119

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.

Upvotes: 10

Views: 18470

Answers (5)

Sulaiman
Sulaiman

Reputation: 101

For Jenkins, you can try this approach as well.

1 1 8-14,21-28 * 5

Upvotes: 0

Siva
Siva

Reputation: 143

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

Upvotes: 5

J.Z.
J.Z.

Reputation: 941

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
}

Upvotes: 3

wincrasher
wincrasher

Reputation: 119

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.

Upvotes: 4

danehammer
danehammer

Reputation: 416

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.

Upvotes: 9

Related Questions