Eval Eval

yaml
type: "io.kestra.plugin.scripts.groovy.Eval"

Execute a Groovy script.

Examples

Make an API call and pass request body to a Groovy script.

yaml
id: api_request_to_groovy
namespace: company.team

tasks:
  - id: request
    type: io.kestra.plugin.core.http.Request
    uri: "https://dummyjson.com/products/1"

  - id: groovy
    type: io.kestra.plugin.scripts.groovy.Eval
    script: |
      logger.info('{{ outputs.request.body }}')

  - id: download
    type: io.kestra.plugin.core.http.Download
    uri: "https://dummyjson.com/products/1"

  - id: run_context_groovy
    type: io.kestra.plugin.scripts.groovy.Eval
    script: |
      // logger.info('Vars: {}', runContext.getVariables())
      URI uri = new URI(runContext.variables.outputs.download.uri)
      InputStream istream = runContext.storage().getFile(uri)
      logger.info('Content: {}', istream.text)
yaml
id: "eval"
type: "io.kestra.plugin.scripts.groovy.Eval"
id: groovy_eval
namespace: company.team

tasks:
  - id: eval
    type: io.kestra.plugin.scripts.groovy.Eval
    outputs:
      - out
      - map
    script: |
      import io.kestra.core.models.executions.metrics.Counter

      logger.info('executionId: {}', runContext.render('{{ execution.id }}'))
      runContext.metric(Counter.of('total', 666, 'name', 'bla'))

      map = Map.of('test', 'here')
      File tempFile = runContext.workingDir().createTempFile().toFile()
      var output = new FileOutputStream(tempFile)
      output.write('555\n666\n'.getBytes())

      out = runContext.storage().putFile(tempFile

Properties

outputs

  • Type: array
  • SubType: string
  • Dynamic:
  • Required:

A list of output variables that will be usable in outputs.

script

  • Type: string
  • Dynamic: ✔️
  • Required:

A full script.

Outputs

outputs

  • Type: object
  • Required:

The captured outputs as declared on task property.

result

  • Type: object
  • Required:

The resulting object.

Mostly the last return of eval (if the language allows it).

Definitions

Was this page helpful?