How to Build a Custom Condition Plugin for Kestra
For the complete documentation index, see llms.txt. For a full content snapshot, see llms-full.txt. Append.mdto anykestra.io/docs/*URL for plain Markdown.
Here is how you can develop a new Condition.
Build a condition plugin for Kestra
Here is a simple condition example that validate the current flow:
java@SuperBuilder
@ToString
@EqualsAndHashCode
@Getter
@NoArgsConstructor
@Schema(
title = "Condition for a specific flow"
)
@Plugin(
examples = {
@Example(
full = true,
code = {
"- conditions:",
" - type: io.kestra.plugin.core.condition.FlowCondition",
" namespace: company.team",
" flowId: my-current-flow"
}
)
}
)
public class FlowCondition extends Condition {
@NotNull
@Schema(title = "The namespace of the flow")
public String namespace;
@NotNull
@Schema(title = "The flow ID")
public String flowId;
@Override
public boolean test(ConditionContext conditionContext) {
return conditionContext.getFlow().getNamespace().equals(this.namespace) && conditionContext.getFlow().getId().equals(this.flowId);
}
}You just need to extend Condition and implement the boolean test(ConditionContext conditionContext) method.
You can have any properties you want for any task such as validation or documentation; everything works the same way.
The test will receive a ConditionContext that will expose:
conditionContext.getFlow(): the current flow.conditionContext.getExecution(): the current execution that can be null for Triggers.conditionContext.getRunContext(): a RunContext to render your properties.
This method must return a boolean to validate the condition.
Documentation
Remember to document your conditions. For this, we provide a set of annotations explained in the Document each plugin section.