Schedule trigger does not run the job when the branch head was already built by that job #3300
christoffers opened 6 minutes ago

A job with a ScheduleTrigger runs only on the days when the branch head has a new commit. If the job has already run on the head commit, with the same parameters, the scheduled trigger does not start a new build. The schedule is then effectively "run after each new commit, at most once a day", not "run every day".

Steps to reproduce

  1. Add a job with a schedule trigger, for example:

    triggers:
      - type: ScheduleTrigger
        cronExpression: 0 0 1 * * ?
        branches: main
    
  2. Let it run once at the scheduled time.

  3. Push no new commit to main.

  4. Wait for the next scheduled time.

Expected behaviour

The job runs again at each scheduled time, on the current head of main, also when that commit was already built by this job.

Actual behaviour

No build is started. A build starts again only on the first scheduled time after a new commit is pushed to main.

The build history of two of our projects shows this. Every scheduled build is on a different commit, and the days with no build are the days after which the branch had no new commit:

JobScheduleScheduled builds
A Renovate job01:00 daily24, 25, 26 November and 2 December only
A Renovate job03:00 daily46 builds in 50 days; no build on 21–22 October, 3–4 and 6–8 November, 28 November – 1 December, each time after no new commit

Why it matters

Some scheduled jobs do not depend on the commit, but on the state of something outside the repository:

  • Dependency updates (the built-in Renovate step). Renovate must run each night to open, rebase and merge its pull requests. When the only expected changes are Renovate's own pull requests, the branch gets no new commit, so Renovate does not run, so its pull requests do not merge. The job stops until a person pushes something.
  • Nightly vulnerability scans. A scan of an unchanged image or lockfile must run again each night, because new advisories are published every day.
  • Any job that checks an external system: expiring certificates, mirrors, backups.

For these jobs, skipping a build because the commit was already built is wrong.

Workarounds we found

  • A parameter that differs on each run. This is not possible from the trigger itself: the parameter values of a schedule trigger are fixed text, and no variable such as the date is available.
  • An external cron that calls POST /~api/job-runs with a date parameter. This works, but it needs a token and a system outside OneDev.

Suggestion

One of:

  1. A schedule trigger always starts a build, also when the commit was already built by the job with the same parameters. The existing reuse can stay for push and pull request triggers.
  2. An option on the schedule trigger, for example "Run even if the commit was already built".
  3. A variable for the trigger time (for example @trigger_time@) that can be used in the parameter values of a schedule trigger, so each run has different parameters.
1/1
Type
Bug
Priority
Normal
Assignee
Affected Versions
17.2.6
Labels
No labels
Issue Votes (0)
Watchers (2)
Reference
OD-3300
Please wait...
Connection lost or session expired, reload to recover
Page is in error, reload to recover