I want Jenkins job to build every two weeks

后端 未结 4 1904
悲哀的现实
悲哀的现实 2020-12-18 00:12

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 a

4条回答
  •  失恋的感觉
    2020-12-18 00:46

    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
    }
    

提交回复
热议问题