Skip to content

JavaScript (node-script@v1) ​

Run JavaScript that needs Node.js modules, network access, the filesystem, or environment variables, with action-owned Node.js.

For data transforms that need none of these, use the built-in js.run step. It runs in an embedded sandbox and needs no Node.js download.

Contributions are welcome. The repository is public, so improvements, bug reports, and pull requests can go to dagucloud/node-script.

Example ​

yaml
steps:
  - id: compute
    action: node-script@v1
    with:
      input:
        version: "1.2.3"
        services: ["api", "worker"]
      script: |
        console.log("preparing release", input.version)

        return {
          tag: `v${input.version}`,
          serviceCount: input.services.length
        }

  - id: print
    run: echo "result=${steps.compute.outputs.result}"
    depends: compute

script is a JavaScript async function body. return publishes result. The action exposes input, params, env, and a captured console object.

Inputs ​

FieldDescription
scriptRequired. JavaScript async function body to run.
inputJSON-compatible value exposed to the script as input.
envExtra environment variables for the script, as a string map.
timeoutSecondsScript timeout in seconds, from 1 to 300. Defaults to 30.

Outputs ​

FieldDescription
oktrue when the script completed successfully.
resultJSON-compatible value returned by the script.
stdoutText written through console.log, console.info, console.debug, or console.dir.
stderrText written through console.warn or console.error.
durationMsWrapper-measured script duration in milliseconds.
nodeVersionNode.js version used by the action.
errorError object when the script fails.

Dagu is open source under the GNU General Public License v3.0.