Skip to content

Commit 3cfe9de

Browse files
committed
add pwsh in shell in
1 parent 8ed5abd commit 3cfe9de

File tree

14 files changed

+53
-39
lines changed

14 files changed

+53
-39
lines changed

core/src/main/java/com/flowci/core/agent/domain/ShellIn.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
import lombok.Setter;
1111
import lombok.experimental.Accessors;
1212

13-
import java.util.LinkedHashSet;
14-
import java.util.LinkedList;
1513
import java.util.List;
1614
import java.util.Set;
1715

@@ -36,7 +34,9 @@ public final class ShellIn extends CmdIn {
3634
@JsonIgnore
3735
private String condition;
3836

39-
private List<String> scripts;
37+
private List<String> bash;
38+
39+
private List<String> pwsh;
4040

4141
private int timeout = 1800;
4242

@@ -48,11 +48,11 @@ public ShellIn() {
4848
super(Type.SHELL);
4949
}
5050

51-
public void addScript(String script) {
51+
public void addBash(String script) {
5252
if (Strings.isNullOrEmpty(script)) {
5353
return;
5454
}
55-
scripts.add(script);
55+
bash.add(script);
5656
}
5757

5858
public void addEnvFilters(Set<String> exports) {

core/src/main/java/com/flowci/core/job/manager/CmdManagerImpl.java

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@
4646
@Component
4747
public class CmdManagerImpl implements CmdManager {
4848

49+
private enum ShellType {
50+
Bash,
51+
52+
PowerShell;
53+
}
54+
4955
@Autowired
5056
private SpringEventManager eventManager;
5157

@@ -60,7 +66,8 @@ public CmdIn createShellCmd(Job job, Step step, NodeTree tree) {
6066
.setCondition(node.getCondition())
6167
.setAllowFailure(node.isAllowFailure())
6268
.setDockers(findDockerOptions(node))
63-
.setScripts(linkScript(node))
69+
.setBash(linkScript(node, ShellType.Bash))
70+
.setPwsh(linkScript(node, ShellType.PowerShell))
6471
.setEnvFilters(linkFilters(node))
6572
.setInputs(linkInputs(node).merge(job.getContext(), false))
6673
.setTimeout(job.getTimeout());
@@ -125,17 +132,24 @@ private Set<String> linkFilters(StepNode current) {
125132
return output;
126133
}
127134

128-
private List<String> linkScript(StepNode current) {
135+
private List<String> linkScript(StepNode current, ShellType shellType) {
129136
List<String> output = new LinkedList<>();
130137

131138
if (current.hasParent()) {
132139
Node parent = current.getParent();
133140
if (parent instanceof StepNode) {
134-
output.addAll(linkScript((StepNode) parent));
141+
output.addAll(linkScript((StepNode) parent, shellType));
135142
}
136143
}
137144

138-
output.add(current.getScript());
145+
if (shellType == ShellType.Bash) {
146+
output.add(current.getBash());
147+
}
148+
149+
if (shellType == ShellType.PowerShell) {
150+
output.add(current.getPwsh());
151+
}
152+
139153
return output;
140154
}
141155

@@ -161,7 +175,7 @@ private void setPlugin(String name, ShellIn cmd) {
161175
cmd.setPlugin(name);
162176
cmd.setAllowFailure(plugin.isAllowFailure());
163177
cmd.addEnvFilters(plugin.getExports());
164-
cmd.addScript(plugin.getScript());
178+
cmd.addBash(plugin.getScript());
165179

166180
// apply docker from plugin as run time if it's specified
167181
ObjectsHelper.ifNotNull(plugin.getDocker(), (docker) -> {

core/src/test/java/com/flowci/core/test/job/CmdManagerTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ public void should_create_cmd_in_with_default_plugin_value() throws IOException
127127

128128
// then:
129129
Vars<String> inputs = cmdIn.getInputs();
130-
List<String> scripts = cmdIn.getScripts();
130+
List<String> scripts = cmdIn.getBash();
131131
Assert.assertEquals(2, scripts.size());
132132

133133
Assert.assertEquals("gittest", cmdIn.getPlugin());
@@ -168,8 +168,8 @@ public void should_handle_step_in_step() throws IOException {
168168
Assert.assertEquals("overwrite-parent", cmdStep2_1.getInputs().get("STEP_2"));
169169

170170
// scripts should be linked
171-
Assert.assertEquals("echo 2", cmdStep2_1.getScripts().get(0));
172-
Assert.assertEquals("echo \"step-2-1\"\n", cmdStep2_1.getScripts().get(1));
171+
Assert.assertEquals("echo 2", cmdStep2_1.getBash().get(0));
172+
Assert.assertEquals("echo \"step-2-1\"\n", cmdStep2_1.getBash().get(1));
173173

174174
// docker should from parent step
175175
Assert.assertEquals("ubuntu:18.04", cmdStep2_1.getDockers().get(0).getImage());
@@ -180,8 +180,8 @@ public void should_handle_step_in_step() throws IOException {
180180
Assert.assertEquals("parent", cmdStep2_2.getInputs().get("STEP_2"));
181181

182182
// scripts should be linked
183-
Assert.assertEquals("echo 2", cmdStep2_2.getScripts().get(0));
184-
Assert.assertEquals("echo \"step-2-2\"\n", cmdStep2_2.getScripts().get(1));
183+
Assert.assertEquals("echo 2", cmdStep2_2.getBash().get(0));
184+
Assert.assertEquals("echo \"step-2-2\"\n", cmdStep2_2.getBash().get(1));
185185

186186
// docker should be applied from step2-2
187187
Assert.assertEquals("redis", cmdStep2_2.getDockers().get(0).getImage());

core/src/test/java/com/flowci/core/test/job/JobServiceTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ public void should_finish_whole_job() throws InterruptedException, IOException {
295295
Assert.assertTrue(cmd.isAllowFailure());
296296
Assert.assertEquals("echo step version", cmd.getInputs().get("FLOW_VERSION"));
297297
Assert.assertEquals("echo step", cmd.getInputs().get("FLOW_WORKSPACE"));
298-
Assert.assertEquals("echo hello\n", cmd.getScripts().get(0));
298+
Assert.assertEquals("echo hello\n", cmd.getBash().get(0));
299299

300300
// when: make dummy response from agent for step 1
301301
firstStep.setStatus(Step.Status.SUCCESS);
@@ -318,7 +318,7 @@ public void should_finish_whole_job() throws InterruptedException, IOException {
318318
cmd = (ShellIn) cmdForStep2.getValue();
319319
Assert.assertEquals(secondStep.getId(), cmd.getId());
320320
Assert.assertFalse(cmd.isAllowFailure());
321-
Assert.assertEquals("echo 2", cmd.getScripts().get(0));
321+
Assert.assertEquals("echo 2", cmd.getBash().get(0));
322322

323323
// when: make dummy response from agent for step 2
324324
secondStep.setStatus(Step.Status.SUCCESS);

core/src/test/resources/flow-all-failure.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ steps:
77
FLOW_WORKSPACE: "echo step"
88
FLOW_VERSION: "echo step version"
99
allow_failure: true
10-
script: |
10+
bash: |
1111
echo hello
1212
1313
- name: step2
1414
allow_failure: true
15-
script: "echo 2"
15+
bash: "echo 2"

core/src/test/resources/flow-with-condition.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ steps:
1212
FLOW_VERSION: "echo step version"
1313
condition: |
1414
return false
15-
script: |
15+
bash: |
1616
echo hello
1717
1818
- name: step2
1919
allow_failure: false
20-
script: "echo 2"
20+
bash: "echo 2"

core/src/test/resources/flow-with-failure.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ steps:
66
- envs:
77
FLOW_WORKSPACE: "echo step"
88
FLOW_VERSION: "echo step version"
9-
script: |
9+
bash: |
1010
echo shoulde failure
1111
12-
- script: |
12+
- bash: |
1313
echo cannot run

core/src/test/resources/flow-with-filter.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ steps:
1111
FLOW_WORKSPACE: "echo step"
1212
FLOW_VERSION: "echo step version"
1313
allow_failure: true
14-
script: |
14+
bash: |
1515
echo hello
1616
1717
- name: step2
1818
allow_failure: false
19-
script: "echo 2"
19+
bash: "echo 2"

core/src/test/resources/flow-with-notify.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ steps:
1212
FLOW_WORKSPACE: "echo step"
1313
FLOW_VERSION: "echo step version"
1414
allow_failure: true
15-
script: |
15+
bash: |
1616
echo hello
1717
1818
- name: step2
1919
allow_failure: false
20-
script: "echo 2"
20+
bash: "echo 2"

core/src/test/resources/flow-with-plugin-not-found.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ steps:
77
FLOW_WORKSPACE: "echo step"
88
FLOW_VERSION: "echo step version"
99
allow_failure: true
10-
plugin: "not found.."
10+
bash: "not found.."
1111

1212
- name: step2
1313
allow_failure: false
14-
script: "echo 2"
14+
bash: "echo 2"

0 commit comments

Comments
 (0)