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: dev
tasks:
- id: request
type: io.kestra.plugin.fs.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.fs.http.Download
uri: "https://dummyjson.com/products/1"
- id: runContextGroovy
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.uriToInputStream(uri)
logger.info('Content: {}', istream.text)
yaml
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.tempFile().toFile()
var output = new FileOutputStream(tempFile)
output.write('555\n666\n'.getBytes())
out = runContext.putTempFile(tempFile)
Properties
outputs
- Type: array
- SubType: string
- Dynamic: ❌
- Required: ❌
A List of outputs variables that will be usable in outputs.
script
- Type: string
- Dynamic: ✔️
- Required: ❌
A full script
Outputs
outputs
- Type: object
The captured outputs as declared on task property.
result
- Type: object
The resulting object
Mostly the last return of eval (if the language allow it)