Class Script

java.lang.Object
io.kestra.core.models.tasks.Task
io.kestra.plugin.scripts.exec.AbstractExecScript
io.kestra.plugin.scripts.r.Script
All Implemented Interfaces:
io.kestra.core.models.Plugin, io.kestra.core.models.tasks.InputFilesInterface, io.kestra.core.models.tasks.NamespaceFilesInterface, io.kestra.core.models.tasks.OutputFilesInterface, io.kestra.core.models.tasks.RunnableTask<io.kestra.plugin.scripts.exec.scripts.models.ScriptOutput>, io.kestra.core.models.tasks.TaskInterface, io.kestra.core.models.WorkerJobLifecycle

@Example(title="Install a package and execute an R script",code={"script: |"," library(lubridate)"," ymd(\"20100604\");"," mdy(\"06-04-2011\");"," dmy(\"04/06/2012\")","beforeCommands:"," - Rscript -e \'install.packages(\"lubridate\")\'"}) @Example(full=true,title="Add an R script in the embedded VS Code editor, install required packages and execute it.\n\nHere is an example R script that you can add in the embedded VS Code editor. You can name the script file `main.R`:\n\n```r\nlibrary(dplyr)\nlibrary(arrow)\n\ndata(mtcars) # load mtcars data\nprint(head(mtcars))\n\nfinal <- mtcars %>%\n summarise(\n avg_mpg = mean(mpg),\n avg_disp = mean(disp),\n avg_hp = mean(hp),\n avg_drat = mean(drat),\n avg_wt = mean(wt),\n avg_qsec = mean(qsec),\n avg_vs = mean(vs),\n avg_am = mean(am),\n avg_gear = mean(gear),\n avg_carb = mean(carb)\n )\nfinal %>% print()\nwrite.csv(final, \"final.csv\")\n\nmtcars_clean <- na.omit(mtcars) # this line removes rows with NA values\nwrite_parquet(mtcars_clean, \"mtcars_clean.parquet\")\n```\n\nNote that tasks in Kestra are stateless. Therefore, the files generated by a task, such as the CSV and Parquet files in the example above, are not persisted in Kestra\'s internal storage, unless you explicitly tell Kestra to do so. Make sure to add the `outputFiles` property to your task as shown below to persist the generated Parquet file (or any other file) in Kestra\'s internal storage and make them visible in the **Outputs** tab.\n\nTo access this output in downstream tasks, use the syntax `{{outputs.yourTaskId.outputFiles[\'yourFileName.fileExtension\']}}`. Alternatively, you can wrap your tasks that need to pass data between each other in a `WorkingDirectory` task \u2014 this way, those tasks will share the same working directory and will be able to access the same files.\n\nNote how we use the `read` function to read the content of the R script stored as a [Namespace File](https://kestra.io/docs/developer-guide/namespace-files).\n\nFinally, note that the `docker` property is optional. If you don\'t specify it, Kestra will use the default R image. If you want to use a different image, you can specify it in the `docker` property as shown below.\n",code="id: rCars\nnamespace: company.team\ntasks:\n - id: r\n type: io.kestra.plugin.scripts.r.Script\n warningOnStdErr: false\n containerImage: ghcr.io/kestra-io/rdata:latest\n script: \"{{ read(\'main.R\') }}\"\n outputFiles:\n - \"*.csv\"\n - \"*.parquet\"\n") public class Script extends io.kestra.plugin.scripts.exec.AbstractExecScript
  • Nested Class Summary

    Nested classes/interfaces inherited from class io.kestra.plugin.scripts.exec.AbstractExecScript

    io.kestra.plugin.scripts.exec.AbstractExecScript.AbstractExecScriptBuilder<C extends io.kestra.plugin.scripts.exec.AbstractExecScript,B extends io.kestra.plugin.scripts.exec.AbstractExecScript.AbstractExecScriptBuilder<C,B>>

    Nested classes/interfaces inherited from class io.kestra.core.models.tasks.Task

    io.kestra.core.models.tasks.Task.TaskBuilder<C extends io.kestra.core.models.tasks.Task,B extends io.kestra.core.models.tasks.Task.TaskBuilder<C,B>>
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected String
     
    protected @NotNull @NotEmpty String
     

    Fields inherited from class io.kestra.plugin.scripts.exec.AbstractExecScript

    beforeCommands, docker, env, failFast, interpreter, runner, targetOS, taskRunner, warningOnStdErr

    Fields inherited from class io.kestra.core.models.tasks.Task

    disabled, id, retry, timeout, type
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected io.kestra.plugin.scripts.exec.scripts.models.DockerOptions
    injectDefaults(io.kestra.plugin.scripts.exec.scripts.models.DockerOptions original)
     
    io.kestra.plugin.scripts.exec.scripts.models.ScriptOutput
    run(io.kestra.core.runners.RunContext runContext)
     

    Methods inherited from class io.kestra.plugin.scripts.exec.AbstractExecScript

    canEqual, commands, equals, getBeforeCommands, getBeforeCommandsWithOptions, getContainerImage, getDocker, getEnv, getExitOnErrorCommands, getFailFast, getInputFiles, getInterpreter, getNamespaceFiles, getOutputDirectory, getOutputFiles, getRunner, getTargetOS, getTaskRunner, getWarningOnStdErr, hashCode, kill, mayAddExitOnErrorCommands, toString

    Methods inherited from class io.kestra.core.models.tasks.Task

    findById, findById, getDescription, getDisabled, getId, getLogLevel, getRetry, getTimeout, getType, getWorkerGroup, isAllowFailure, isFlowable, isSendToWorkerTask

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait

    Methods inherited from interface io.kestra.core.models.WorkerJobLifecycle

    stop
  • Field Details

    • containerImage

      protected String containerImage
    • script

      @PluginProperty(dynamic=true) @NotNull @NotEmpty protected @NotNull @NotEmpty String script
  • Constructor Details

    • Script

      public Script()
  • Method Details

    • injectDefaults

      protected io.kestra.plugin.scripts.exec.scripts.models.DockerOptions injectDefaults(io.kestra.plugin.scripts.exec.scripts.models.DockerOptions original)
      Overrides:
      injectDefaults in class io.kestra.plugin.scripts.exec.AbstractExecScript
    • run

      public io.kestra.plugin.scripts.exec.scripts.models.ScriptOutput run(io.kestra.core.runners.RunContext runContext) throws Exception
      Throws:
      Exception