diff --git a/digdag-docs/src/operators/sh.md b/digdag-docs/src/operators/sh.md index 5c37a4b24b..bdde105e25 100644 --- a/digdag-docs/src/operators/sh.md +++ b/digdag-docs/src/operators/sh.md @@ -33,7 +33,23 @@ The shell defaults to `/bin/sh`. If an alternate shell such as `zsh` is desired, +step1: sh>: tasks/step2.sh -On Windows, you can set PowerShell.exe to the `shell` option: +On Windows, you can set PowerShell.exe to the `shell` option. +Since ver.0.10.6, it is correct to specify ["powershell.exe"], +but digdag works with ["powershell.exe", "-"] in ver.0.9.46 +or earlier. + +>= 0.10.6 + _export: + sh: + shell: ["powershell.exe"] + + +step1: + sh>: step1.exe + + +step2: + sh>: step2.ps1 + +<= 0.9.46 _export: sh: diff --git a/digdag-standards/src/main/java/io/digdag/standards/operator/ShOperatorFactory.java b/digdag-standards/src/main/java/io/digdag/standards/operator/ShOperatorFactory.java index aec2de7872..f8ad15aff3 100644 --- a/digdag-standards/src/main/java/io/digdag/standards/operator/ShOperatorFactory.java +++ b/digdag-standards/src/main/java/io/digdag/standards/operator/ShOperatorFactory.java @@ -128,28 +128,42 @@ private void runCode(final Config state) } } + private List getShell(final Config params, final Boolean winOS){ + // Until digdag ver. 0.9, it was necessary to write ["powershell.exe","-"] to specify shell, + // but since ver. 0.10, jobs are not executed unless ["powershell.exe"] is written. + // To cope with the sudden incompatibility, change the shell specification ["powershell.exe","-"] + // to ["powershell.exe"]. + // In addition, a deprecation message is output. This conversion will be removed in the future. + List temp_shell; + if (params.has("shell")) { + temp_shell = params.getListOrEmpty("shell", String.class); + if (temp_shell.get(0).toLowerCase().equals("powershell.exe") && temp_shell.size() == 2){ + if (temp_shell.get(1).equals("-")){ + temp_shell.remove(1); + logger.info("Removed \"-\" from shell specification --- from [\"powershell.exe\",\"-\"] to [\"powershell.exe\"] ."); + } + } + } + else { + temp_shell = ImmutableList.of(winOS ? "PowerShell.exe" : "/bin/sh"); + } + return temp_shell; + } + private CommandStatus runCommand(final Config params, final CommandContext commandContext) throws IOException, InterruptedException { final Path tempDir = workspace.createTempDir(String.format("digdag-sh-%d-", request.getTaskId())); final Path workingDirectory = workspace.getPath(); // absolute - final Path runnerPath = tempDir.resolve("runner.sh"); // absolute + final Boolean winOS = isWindowsPlatform(); + final Path runnerPath = tempDir.resolve(winOS ? "runner.ps1" : "runner.sh"); // absolute - final List shell; - if (params.has("shell")) { - shell = params.getListOrEmpty("shell", String.class); - } - else { - shell = ImmutableList.of("/bin/sh"); - } + final List shell = getShell(params, winOS); final ImmutableList.Builder cmdline = ImmutableList.builder(); - if (params.has("shell")) { - cmdline.addAll(shell); - } - else { - cmdline.addAll(shell); - } + + cmdline.addAll(shell); + cmdline.add(workingDirectory.relativize(runnerPath).toString()); // relative final String shScript = UserSecretTemplate.of(params.get("_command", String.class)) @@ -223,5 +237,14 @@ private CommandRequest buildCommandRequest(final CommandContext commandContext, .ioDirectory(ioDirectory) .build(); } + + private boolean isWindowsPlatform() + { + final String os = System.getProperty("os.name").toLowerCase(); + if ( os.startsWith("windows")) { + return true; + } + return false; + } } }