How to launch a job at 11pm only when there was a new push

I would go with dynamic child pipelines. And a reference here.

Something in this nature:

generate childpipeline:
  rules:
    - if: '$CI_PIPELINE_SOURCE == "schedule"'
      when: always
    - when: never
  script:
    - some_very_smart_script > .child-gitlab-ci.yml
  artifacts:
    paths:
      - .child-gitlab-ci.yml

trigger child pipeline:
  rules:
    - if: '$CI_PIPELINE_SOURCE == "schedule"'
      when: always
    - when: never
  needs:
    - 'generate childpipeline'
  trigger:
    include:
      - artifact: .child-gitlab-ci.yml
        job: 'generate childpipeline'
    strategy: depend

The key component will be the some_very_smart_script that would need to fetch git history and determine what branch had push in last xy hours. While getting date of a push is not easy thing there are some options, but I haven’t tried them with GitLab. After you get that info you can generate the child pipeline file which would include job you need. Last point would be if this can be done on another branch.

1 Like