Skip to content

Commit

Permalink
feat: add env var to the SSH Command task
Browse files Browse the repository at this point in the history
  • Loading branch information
loicmathieu committed Apr 5, 2024
1 parent e70d875 commit c9e3f41
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/main/java/io/kestra/plugin/fs/ssh/Command.java
Expand Up @@ -13,6 +13,7 @@
import io.kestra.core.models.tasks.Task;
import io.kestra.core.runners.RunContext;
import io.kestra.core.tasks.PluginUtilsService;
import io.kestra.core.utils.MapUtils;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Builder;
import lombok.EqualsAndHashCode;
Expand Down Expand Up @@ -98,6 +99,15 @@ public class Command extends Task implements SshInterface, RunnableTask<Command.
@Builder.Default
private String strictHostKeyChecking = "no";

@Schema(
title = "Environment variables to pass to the SSH process."
)
@PluginProperty(
additionalProperties = String.class,
dynamic = true
)
protected Map<String, String> env;

@Builder.Default
@Schema(
title = "Use `WARNING` state if any stdErr is sent"
Expand All @@ -108,7 +118,7 @@ public class Command extends Task implements SshInterface, RunnableTask<Command.

@Override
public Command.ScriptOutput run(RunContext runContext) throws Exception {
JSch jsch = null;
JSch jsch;
Session session = null;
ChannelExec channel = null;
LogThread stdOut = null;
Expand Down Expand Up @@ -163,6 +173,12 @@ else if (authMethod == AuthMethod.PUBLIC_KEY) {
stdOut = threadLogSupplier(runContext).apply(inStream, false);
stdErr = threadLogSupplier(runContext).apply(inErrStream, true);

if (this.env != null) {
for(var entry : env.entrySet()) {
channel.setEnv(runContext.render(entry.getKey()), runContext.render(entry.getValue()));
}
}

channel.connect();
while (channel.isConnected()) {
Thread.sleep(SLEEP_DELAY_MS);
Expand Down

0 comments on commit c9e3f41

Please sign in to comment.