Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

exitCode does not exist when task fails for io.kestra.plugin.scripts.shell.Commands #4020

Open
Tracked by #4706
wrussell1999 opened this issue Jun 13, 2024 · 4 comments
Labels
bug Something isn't working

Comments

@wrussell1999
Copy link
Member

Describe the issue

When using io.kestra.plugin.scripts.shell.Script, it seems to only give the output exitCode if it succeeds. The example below doesn't generate exitCode so the second task fails.

id: exit-codes
namespace: example
tasks: 
  - id: task1 
    type: io.kestra.plugin.scripts.shell.Commands
    commands:  
      - exit 1
    allowFailure: true

  - id: task2 
    type: io.kestra.plugin.core.debug.Return 
    format: "{{ outputs.task1.exitCode }}"

Unable to find exitCode used in the expression {{ outputs.task1.exitCode }} at line 1

It should return an exitCode when it fails and allowFailure is set to true

Seems to also be an issue for the SSH plugin: #4016

Environment

  • Kestra Version: 0.18 Snapshot
@wrussell1999 wrussell1999 added the bug Something isn't working label Jun 13, 2024
@wrussell1999 wrussell1999 changed the title exitCode is does not exist when task fails for io.kestra.plugin.scripts.shell.Commands exitCode does not exist when task fails for io.kestra.plugin.scripts.shell.Commands Jun 13, 2024
@anna-geller
Copy link
Member

@loicmathieu is this feasible? if so, how difficult would it be to persist outputs like this one in a failed task with allowFailure? I'm aware we discussed this in the past but I admit I no longer remember what was the decision here

if not feasible, you can directly close and we can consider clarifying it in the Script docs

@anna-geller
Copy link
Member

similar request kestra-io/plugin-dbt#112

@loicmathieu
Copy link
Member

Yes, it's a refactoring that needs to be done on all script and CLI task to: in case of script exception, return the output with the exit code instead of throwing the exception, then set the task to FAIL.

@johnkm516
Copy link

Scripts and CLI tasks should definitely handle this automatically, but as a temporary workaround for anyone dealing with this you can do something like this :

id: batch-cm-log
namespace: erp.cm

tasks:
  - id: start_batch
    type: io.kestra.plugin.fs.ssh.Command
    commands:
      - cd /app/instances/cm-bat
      - output=$(./springBatch.sh batchStoreDailySales}})
      - exit_code=$?
      - echo $output
      - exit $exit_code
    host: "{{ secret('batch.host') }}"  
    password: "{{ secret('batch.password') }}"
    username: "{{ secret('batch.username') }}"

Works with script blocks as well, like this :

     - { echo "Running command 1"; echo "Running command 2"; false; echo "Running command 3"; }
     - exit_code=$?
     - exit $exit_code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Backlog
Development

No branches or pull requests

4 participants