Skip to content

Introduce ScriptTrigger & CommandsTrigger for the Node plugin #320

Description

@fdelbrayelle

Feature description

Take inspiration from what has been done for Shell sub plugin

Activity

  1. added
    area/plugin
    good first issue
    on Jan 20, 2026
  2. idivanshu commented on Jan 25, 2026

    @idivanshu
    Contributor

    Can i take this up? Also here the node means node js or something else ?

  3. fdelbrayelle commented on Jan 26, 2026

    @fdelbrayelle
    MemberAuthor

    Hi @idivanshu 👋 Yes it means Node JS, thanks!

  4. idivanshu commented on Jan 27, 2026

    @idivanshu
    Contributor

    Hi @fdelbrayelle

    While implementing Node ScriptTrigger / CommandsTrigger, I followed the Shell trigger reference from
    #317

    My code file - https://github.com/idivanshu/plugin-scripts/blob/main/plugin-script-node/src/main/java/io/kestra/plugin/scripts/node/ScriptTrigger.java
    What works

    Node tasks work fine with Docker when executed inside a flow:

    tasks:
      - id: script
        type: io.kestra.plugin.scripts.node.Script
        script: |
          console.log("hello")

    What fails

    Running the same logic from a trigger using Docker:

    Script task = Script.builder()
        .id("node-script-trigger")
        .taskRunner(Docker.builder().build())
        .script(this.script)
        .build();
    
    task.run(runContext);

    Results in:

    Cannot invoke "java.util.Map.get(Object)" because "task" is null
    at ScriptService.labels(...)
    

    Reason

    Triggers run before an execution exists, so RunContext has no task metadata.

    Docker runner expects task labels; Process runner (used by Shell triggers) does not.

    Question
    Is it expected that Node triggers should also rely on Process.instance() (like Shell triggers), meaning Node must be available on the host?
    Or is there a supported way to run Docker-based scripts from triggers in the current core?

    Thanks 🙏

  5. MilosPaunovic commented on Jan 29, 2026

    @MilosPaunovic
    Member

    Hey @idivanshu, are there any updates on this?

  6. idivanshu commented on Jan 29, 2026

    @idivanshu
    Contributor

    Hey @idivanshu, are there any updates on this?
    Hi @MilosPaunovic
    had some query about implementation, already asked to @fdelbrayelle (#320 (comment)), waiting for his suggestions

  7. fdelbrayelle commented on Jan 29, 2026

    @fdelbrayelle
    MemberAuthor

    Hi @idivanshu 👋 Did you try to simply remove .taskRunner(...)?

    Else maybe we should (on plugin-script-shell too) add a taskRunner property like this also in ScriptTrigger and CommandsTrigger to let the user choose and override it at the call:

        @PluginProperty
        @Builder.Default
        @Valid
        protected TaskRunner<?> taskRunner = Docker.builder()
            .type(Docker.class.getName())
            .pullPolicy(Property.ofValue(PullPolicy.IF_NOT_PRESENT))
            .build();
    
  8. idivanshu commented on Jan 29, 2026

    @idivanshu
    Contributor

    Hi @idivanshu 👋 Did you try to simply remove .taskRunner(...)?

    Else maybe we should (on plugin-script-shell too) add a taskRunner property like this also in ScriptTrigger and CommandsTrigger to let the user choose and override it at the call:

        @PluginProperty
        @Builder.Default
        @Valid
        protected TaskRunner<?> taskRunner = Docker.builder()
            .type(Docker.class.getName())
            .pullPolicy(Property.ofValue(PullPolicy.IF_NOT_PRESENT))
            .build();
    

    Observations

    Case 1: ScriptTrigger with explicit Docker taskRunner

    Script task = Script.builder()
        .taskRunner(Docker.builder().build())
        .containerImage(this.containerImage)
        .script(this.script)
        .build();
    
    
    • Build succeeds
    • Runtime fails with NullPointerException
    • Error seen in ScriptService.labels (task == null)

    Case 2: ScriptTrigger without .taskRunner(...)

    Script task = Script.builder()
        .containerImage(this.containerImage)
        .script(this.script)
        .build();
    
    • Trigger runs with Process runner
    • Runtime error: /bin/sh: node: not found
    • Script does not execute successfully
  9. Malaydewangan09 commented on Jan 30, 2026

    @Malaydewangan09
    Member

    @idivanshu, could you try with .taskRunner(Docker.instance())?

  10. 3 remaining items

  11. idivanshu commented on Feb 2, 2026

    @idivanshu
    Contributor

    @idivanshu, maybe lets use the Process runner, and add the docs that this Trigger required node to be available in the host path? cc @fdelbrayelle

    I installed node in docker container manually and it worked actually. I will wrap up CommandTrigger and tests asap and then will raise the PR.
    cc @MilosPaunovic

  12. fdelbrayelle commented on Mar 10, 2026

    @fdelbrayelle
    MemberAuthor

    QA Report — Branch idivanshu-node-triggers

    Tested on: 2026-03-10
    Kestra version: EE standalone (develop)
    Plugin version: plugin-script-node-1.4.1-SNAPSHOT
    Build: ./gradlew shadowJar — all submodule JARs deployed to ~/dev/plugins/


    Summary

    # Flow ID Type Scenario Result
    1 node-script-trigger-exit0 node.ScriptTrigger Script exits 0, condition exit 0 ✅ PASS — trigger fires
    2 node-script-trigger-vars node.ScriptTrigger Script outputs JSON, condition exit 0 ✅ PASS — trigger fires
    3 node-commands-trigger-exit0 node.CommandsTrigger Single command, exit 0 ✅ PASS — trigger fires
    4 node-commands-trigger-multi node.CommandsTrigger Multiple commands in list ❌ BUG — deserialization error
    5 node-script-trigger-nonmatch node.ScriptTrigger exit 0 but condition exit 1 ✅ PASS — trigger correctly does NOT fire
    6 node-script-task node.Script (task) Non-regression: script task ✅ PASS — SUCCESS
    7 node-commands-task node.Commands (task) Non-regression: commands task ✅ PASS — SUCCESS
    8 shell-script-trigger-exit0 shell.ScriptTrigger Non-regression: shell trigger ✅ PASS — trigger fires

    Result: 7/8 PASS, 1 BUG found


    Bug Details — Flow 4: CommandsTrigger with multiple commands

    Severity: Medium — affects multi-command usage of CommandsTrigger

    When commands contains more than one item in the YAML list, the trigger fails with:

    IllegalVariableEvaluationException: Cannot deserialize value of type java.lang.String
    from Object value (token JsonToken.START_OBJECT)
    at Property.deserialize() → Property.asList()
    

    Root cause: The commands property is typed as Property<List<String>>. When the YAML list has multiple entries, Jackson wraps them in a way that Property.asList() cannot deserialize back to List<String>.

    Single command works fine (Flow 3). The issue only manifests with 2+ commands.

    Reproduction flow:

    id: node-commands-trigger-multi
    namespace: qa.triggers
    tasks:
      - id: hello
        type: io.kestra.plugin.core.log.Log
        message: "Commands trigger with multiple commands fired!"
    triggers:
      - id: poll
        type: io.kestra.plugin.scripts.node.CommandsTrigger
        interval: PT10S
        commands:
          - node -e "console.log('step 1')"
          - node -e "console.log('step 2')"
        exitCondition: "exit 0"

    Note: This same pattern works correctly in shell.CommandsTrigger, so the fix likely involves aligning the Node CommandsTrigger implementation with the Shell one.


    Test Flows Used

    Flow 1 — node-script-trigger-exit0
    id: node-script-trigger-exit0
    namespace: qa.triggers
    tasks:
      - id: hello
        type: io.kestra.plugin.core.log.Log
        message: "Node ScriptTrigger with exit 0 fired!"
    triggers:
      - id: poll
        type: io.kestra.plugin.scripts.node.ScriptTrigger
        interval: PT10S
        script: |
          console.log("Hello from Node ScriptTrigger");
        exitCondition: "exit 0"
    Flow 2 — node-script-trigger-vars
    id: node-script-trigger-vars
    namespace: qa.triggers
    tasks:
      - id: hello
        type: io.kestra.plugin.core.log.Log
        message: "ScriptTrigger with vars fired!"
    triggers:
      - id: poll
        type: io.kestra.plugin.scripts.node.ScriptTrigger
        interval: PT10S
        script: |
          const data = JSON.stringify({ status: "ok", count: 42 });
          console.log(data);
        exitCondition: "exit 0"
    Flow 3 — node-commands-trigger-exit0
    id: node-commands-trigger-exit0
    namespace: qa.triggers
    tasks:
      - id: hello
        type: io.kestra.plugin.core.log.Log
        message: "CommandsTrigger with single command fired!"
    triggers:
      - id: poll
        type: io.kestra.plugin.scripts.node.CommandsTrigger
        interval: PT10S
        commands:
          - node -e "console.log('Hello from CommandsTrigger')"
        exitCondition: "exit 0"
    Flow 4 — node-commands-trigger-multi (BUG)
    id: node-commands-trigger-multi
    namespace: qa.triggers
    tasks:
      - id: hello
        type: io.kestra.plugin.core.log.Log
        message: "Commands trigger with multiple commands fired!"
    triggers:
      - id: poll
        type: io.kestra.plugin.scripts.node.CommandsTrigger
        interval: PT10S
        commands:
          - node -e "console.log('step 1')"
          - node -e "console.log('step 2')"
        exitCondition: "exit 0"
    Flow 5 — node-script-trigger-nonmatch (negative test)
    id: node-script-trigger-nonmatch
    namespace: qa.triggers
    tasks:
      - id: hello
        type: io.kestra.plugin.core.log.Log
        message: "This should never fire"
    triggers:
      - id: poll
        type: io.kestra.plugin.scripts.node.ScriptTrigger
        interval: PT10S
        script: |
          console.log("Script runs fine");
        exitCondition: "exit 1"
    Flow 6 — node-script-task (non-regression)
    id: node-script-task
    namespace: qa.tasks
    tasks:
      - id: run_script
        type: io.kestra.plugin.scripts.node.Script
        script: |
          const os = require('os');
          console.log("Hello from Node.js!");
          console.log("Platform:", os.platform());
          console.log("Node version:", process.version);
    Flow 7 — node-commands-task (non-regression)
    id: node-commands-task
    namespace: qa.tasks
    tasks:
      - id: run_commands
        type: io.kestra.plugin.scripts.node.Commands
        commands:
          - node -e "console.log('Hello from Commands task')"
          - node -e "console.log('Node version:', process.version)"
    Flow 8 — shell-script-trigger-exit0 (non-regression)
    id: shell-script-trigger-exit0
    namespace: qa.triggers
    tasks:
      - id: hello
        type: io.kestra.plugin.core.log.Log
        message: "Shell ScriptTrigger fired - non-regression OK"
    triggers:
      - id: poll
        type: io.kestra.plugin.scripts.shell.ScriptTrigger
        interval: PT10S
        script: |
          echo "Hello from Shell ScriptTrigger"
        exitCondition: "exit 0"
  13. Pradumnasaraf commented on May 26, 2026

    @Pradumnasaraf
    Member

    Both io.kestra.plugin.scripts.node.ScriptTrigger and io.kestra.plugin.scripts.node.CommandsTrigger are broken.

    In both cases the script or command runs and exits non-zero, but no execution is created. The scheduler immediately logs:
    No execution found, schedule is blocked since ...

    The trigger never recovers. Every later poll repeats the same warning.

    Repro flow: ScriptTrigger:

    id: node_script_trigger
    namespace: qa.triggers
    
    tasks:
      - id: log
        type: io.kestra.plugin.core.log.Log
        message: "node ScriptTrigger fired: exitCode={{ trigger.exitCode }} condition={{ trigger.condition }}"
    
    triggers:
      - id: node_script_fail
        type: io.kestra.plugin.scripts.node.ScriptTrigger
        interval: PT10S
        exitCondition: "exit 1"
        edge: true
        containerImage: node:20-slim
        script: |
          throw new Error("boom");

    Repro flow: CommandsTrigger:

    id: node_commands_trigger
    namespace: qa.triggers
    
    tasks:
      - id: log
        type: io.kestra.plugin.core.log.Log
        message: "node CommandsTrigger fired: exitCode={{ trigger.exitCode }} condition={{ trigger.condition }}"
    
    triggers:
      - id: node_commands_fail
        type: io.kestra.plugin.scripts.node.CommandsTrigger
        interval: PT10S
        exitCondition: "exit 1"
        edge: true
        containerImage: node:20-slim
        commands:
          - node -e "throw new Error('boom')"

    Re-opening this issue.

  14. self-assigned this
    on May 26, 2026
  15. added a commit that references this issue on Jun 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

area/plugingood first issue

Fields

Stage

Done

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions