fix(script): targetOS must be rendered

This commit is contained in:
Loïc Mathieu
2025-01-29 10:25:13 +01:00
parent c5e7b42819
commit 3e8d32cfca

View File

@@ -15,7 +15,6 @@ import io.kestra.plugin.scripts.exec.scripts.runners.CommandsWrapper;
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;
@@ -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(
@@ -179,11 +179,11 @@ public abstract class AbstractExecScript extends Task implements RunnableTask<Sc
}
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;
}
@@ -192,9 +192,12 @@ public abstract class AbstractExecScript extends Task implements RunnableTask<Sc
* 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.