我希望詹金斯的工作每两周建一次

时间:2015-11-18 16:23:09

标签: jenkins

这个表达式会在每个星期五中午运行构建吗?假设我在周五设置了这个?

0 12 * * * / 14

我尝试了0 12 * * FRI / 14,但Jenkins返回错误。

我试图每两周运行一次代码报告工作来匹配scrum。

4 个答案:

答案 0 :(得分:3)

您必须在构建脚本中添加一些逻辑,以确定它是否在上周运行,然后每周运行一次。

我查看了类似的cron作业问题,你必须做一些shell魔术才能使它工作。

您可以尝试使用建议here

H H 8-14,22-28 * 5

这将符合本月第二或第四周的星期五。

答案 1 :(得分:2)

我有同样的问题,我发现的简单工作是创建另一个每周运行的工作 这个工作是一个简单的groovy脚本,它执行以下操作:

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

由于Jenkins不提供功能,因此我能找到最好的解决方案。如果您有更好的解决方案,请随时告诉我。

答案 2 :(得分:1)

一个看起来可笑但可行的答案:安排您的作业每周运行,然后在作业顶部添加以下内容:

// 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
}

答案 3 :(得分:1)

它将每隔星期五中午运行 00 12 * / 2 * 5