drone / proposal

Drone Project Design Documents
13 stars 4 forks source link

Not possible to trigger by specific cron event as well as other events in Drone #34

Open b-dalton opened 2 years ago

b-dalton commented 2 years ago

I have noticed a limitation with Drone in that in order to trigger by multiple events, all events must be true and therefore it is not possible to trigger by a specific cron event in Drone or a push to master/main for example. (Triggers | Drone)

image

It is possible to trigger by cron or push to a branch by using include, however this will trigger on every cron schedule defined in Drone and it isn't possible to specify a specific cron schedule for the event. image

Would be great if this functionality could be added in the near future. (I've searched multiple forums to check if I was approaching it wrong or this functionality existed but had no luck. If I've missed something and this is possible to do with Drone, please let me know. Thanks)

ShruthiHubb commented 2 years ago

Hi @b-dalton you can follow these docs:

  1. https://docs.drone.io/cron/
  2. https://discourse.drone.io/t/add-a-cronjob-with-specific-time-and-specific-branch/7479

Sharing the relevant release notes and API documentation:

  1. https://github.com/harness/drone/blob/master/CHANGELOG.md#150---2019-09-28
  2. https://docs.drone.io/api/cron/cron_trigger/

Feel free to reach out if you need any help.

b-dalton commented 2 years ago

Hi @ShruthiHubb , thanks for your response. The issue is not that I'm not able to set a cron job for a branch (I am able to do this with no issues) but that I'm not able to trigger a pipeline by a cron job OR a push to a branch (e.g. trigger pipeline at 5am daily or when there is a push to master branch). As stated in my original post and screenshot which highlight the documentation, both events must be true and therefore it isn't possible as the cron job event is only true at its scheduled time and therefore the pipeline is not triggered on a push to the branch either.

ShruthiHubb commented 2 years ago

@b-dalton got it! let me get back to you with some solution.

ShruthiHubb commented 2 years ago

@b-dalton can you share the .drone.yml file?

b-dalton commented 2 years ago

Hi @ShruthiHubb , here's one of the pipelines we tried to trigger on a specific cron job as well as a push to master. We had to resort to duplicating the pipelines to separate them so this one is only the push event since it's not possible to have both

kind: pipeline
name: Publish ECR images - master
type: docker

trigger:
  branch:
    - master
  event:
    - push

common_publish_config: &common_publish_config
  registry: REDACTED 
  region: eu-west-2
  tags:
    - latest
    - ${DRONE_COMMIT_SHA}
    - link-${DRONE_BUILD_NUMBER}
    - ci-${DRONE_BUILD_NUMBER}

steps:

This one below is a duplicate of the above pipeline but with the cron event trigger with the specific cron job. We specify the cron job defined in drone ("nightly-master-build")

kind: pipeline
name: Publish ECR images - Nightly master build
type: docker

trigger:
  branch:
    - master
  event:
    - cron
  cron:
    - nightly-master-build

common_publish_config: &common_publish_config
  registry: REDACTED
  region: eu-west-2
  tags:
    - ${DRONE_COMMIT_SHA}
    - nightly-${DRONE_BUILD_NUMBER}

steps:
ShruthiHubb commented 2 years ago

@b-dalton hey thanks for sharing. Let me check and get back to you.

WillGibson commented 2 years ago

@ShruthiHubb It would be amazing if we were able to write expressions to be evaluated for the trigger. We would be able to remove a large amount of duplicated pipeline code if that were possible.