Skip to content

Commit

Permalink
fix(script): targetOS must be rendered
Browse files Browse the repository at this point in the history
  • Loading branch information
loicmathieu committed Jan 29, 2025
1 parent c5e7b42 commit 3e8d32c
Showing 1 changed file with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import io.kestra.plugin.scripts.runner.docker.Docker;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.*;
import lombok.experimental.SuperBuilder;
Expand Down Expand Up @@ -106,6 +105,7 @@ public abstract class AbstractExecScript extends Task implements RunnableTask<Sc
title = "The target operating system where the script will run."
)
@Builder.Default
@NotNull
protected Property<TargetOS> targetOS = Property.of(TargetOS.AUTO);

@Schema(
Expand Down Expand Up @@ -179,11 +179,11 @@ protected List<String> mayAddExitOnErrorCommands(List<String> commands, RunConte
}

if (commands == null || commands.isEmpty()) {
return getExitOnErrorCommands();
return getExitOnErrorCommands(runContext);
}

ArrayList<String> newCommands = new ArrayList<>(commands.size() + 1);
newCommands.addAll(getExitOnErrorCommands());
newCommands.addAll(getExitOnErrorCommands(runContext));
newCommands.addAll(commands);
return newCommands;
}
Expand All @@ -192,9 +192,12 @@ protected List<String> mayAddExitOnErrorCommands(List<String> commands, RunConte
* Gets the list of additional commands to be used for defining interpreter errors handling.
* @return list of commands;
*/
protected List<String> getExitOnErrorCommands() {
protected List<String> getExitOnErrorCommands(RunContext runContext) throws IllegalVariableEvaluationException {
TargetOS rendered = runContext.render(this.getTargetOS()).as(TargetOS.class).orElseThrow();

// If targetOS is Windows OR targetOS is AUTO && current system is windows and we use process as a runner.(TLDR will run on windows)
if (this.getTargetOS().equals(TargetOS.WINDOWS) || this.getTargetOS().equals(TargetOS.AUTO) && SystemUtils.IS_OS_WINDOWS && this.getTaskRunner() instanceof Process) {
if (rendered == TargetOS.WINDOWS ||
(rendered == TargetOS.AUTO && SystemUtils.IS_OS_WINDOWS && this.getTaskRunner() instanceof Process)) {
return List.of("");
}
// errexit option may be unsupported by non-shell interpreter.
Expand Down

0 comments on commit 3e8d32c

Please sign in to comment.