# Develop your Trigger

Here are the instructions to develop a Trigger.

Here is a simple Trigger example that will trigger an execution randomly:

public class Trigger extends AbstractTrigger implements PollingTriggerInterface, TriggerOutput<Trigger.Random> {
    private final Duration interval = Duration.ofSeconds(60);

    protected Double min = 0.5;

    public Optional<Execution> evaluate(RunContext runContext, TriggerContext context) throws Exception {
        Logger logger = runContext.logger();
        double random = Math.random();

        if (random < this.min) {
            return Optional.empty();

        Execution execution = Execution.builder()
            .state(new State())

        return Optional.of(execution);

    public class Random implements io.kestra.core.models.tasks.Output {
        private Double random;

You just need to extend PollingTriggerInterface and implement the Optional<Execution> evaluate(RunContext runContext, TriggerContext context) method.

You can have any properties you want like for any task (validation, documentation, ...), everything is working the same way.

The test will receive these arguments:

  • RunContext runContext: a RunContext in order to render your properties.
  • TriggerContext context: to have the context of this call (flow, execution, trigger, date, ...).

In this method, you add any logic you want: connect to a database, connect to remote file systems, ...
You don't have to take care of resources, Kestra will run this method in its own thread.

This method must simply return an Optional<Execution> with:

  • Optional.empty(): if the condition is not validated.
  • Optional.of(execution): with the execution created if the condition is validated.

You have to provide a TriggerOutput<T> for any output needed (result of query, result of file system listing, ...) that will be available for the flow tasks withing the {{ trigger.* }} variables.


Take care that the trigger must free the resource for the next evaluation. For each interval, this method will be called and if the condition are met, an execution will be created.

To avoid this, move the file or remove the record from the database ; take an action to avoid an infinite triggering.

# Documentation

Remember to document your triggers. For this, we provide a set of annotations explained in the Document each plugin section.