Class WorkingDirectory

All Implemented Interfaces:
FlowableTask<VoidOutput>, NamespaceFilesInterface
Direct Known Subclasses:
Worker

@Example(full=true,title="Clone a git repository into the Working Directory and run a Python script",code={"id: gitPython","namespace: dev","","tasks:"," - id: wdir"," type: io.kestra.core.tasks.flows.WorkingDirectory"," tasks:"," - id: cloneRepository"," type: io.kestra.plugin.git.Clone"," url: https://github.com/kestra-io/examples"," branch: main"," - id: python"," type: io.kestra.plugin.scripts.python.Commands"," docker:"," image: ghcr.io/kestra-io/pydata:latest"," commands:"," - python scripts/etl_script.py"}) @Example(full=true,title="Add input and output files within a Working Directory to use them in a Python script",code="id: apiJSONtoMongoDB\nnamespace: dev\n\ntasks:\n- id: wdir\n type: io.kestra.core.tasks.flows.WorkingDirectory\n tasks:\n - id: demoSQL\n type: io.kestra.core.tasks.storages.LocalFiles\n inputs:\n query.sql: |\n SELECT sum(total) as total, avg(quantity) as avg_quantity\n FROM sales;\n\n - id: inlineScript\n type: io.kestra.plugin.scripts.python.Script\n runner: DOCKER\n docker:\n image: python:3.11-slim\n beforeCommands:\n - pip install requests kestra > /dev/null\n warningOnStdErr: false\n script: |\n import requests\n import json\n from kestra import Kestra\n\n with open(\'query.sql\', \'r\') as input_file:\n sql = input_file.read()\n\n response = requests.get(\'https://api.github.com\')\n data = response.json()\n\n with open(\'output.json\', \'w\') as output_file:\n json.dump(data, output_file)\n\n Kestra.outputs({\'receivedSQL\': sql, \'status\': response.status_code})\n\n - id: jsonFiles\n type: io.kestra.core.tasks.storages.LocalFiles\n outputs:\n - output.json\n\n- id: loadToMongoDB\n type: io.kestra.plugin.mongodb.Load\n connection:\n uri: mongodb://host.docker.internal:27017/\n database: local\n collection: github\n from: \"{{outputs.jsonFiles.uris[\'output.json\']}}\"\n") @Example(full=true,code={"id: working-directory","namespace: io.kestra.tests","","tasks:"," - id: working-directory"," type: io.kestra.core.tasks.flows.WorkingDirectory"," tasks:"," - id: first"," type: io.kestra.plugin.scripts.shell.Commands"," commands:"," - \'echo \"{{ taskrun.id }}\" > {{ workingDir }}/stay.txt\'"," - id: second"," type: io.kestra.plugin.scripts.shell.Commands"," commands:"," - |"," echo \'::{\"outputs\": {\"stay\":\"\'$(cat {{ workingDir }}/stay.txt)\'\"}}::\'"}) @Example(full=true,title="A working directory with a cache of the node_modules directory",code="id: node-with-cache\nnamespace: dev\ntasks:\n - id: working-dir\n type: io.kestra.core.tasks.flows.WorkingDirectory\n cache:\n patterns:\n - node_modules/**\n ttl: PT1H\n tasks:\n - id: script\n type: io.kestra.plugin.scripts.node.Script\n beforeCommands:\n - npm install colors\n script: |\n const colors = require(\"colors\");\n console.log(colors.red(\"Hello\"));") public class WorkingDirectory extends Sequential implements NamespaceFilesInterface