Skip to content

Commit 696cb99

Browse files
author
Yang Guo
committed
fix var from ui not have top priority
1 parent fb21e79 commit 696cb99

File tree

3 files changed

+15
-10
lines changed

3 files changed

+15
-10
lines changed

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

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,8 @@ public CmdId createId(Job job, StepNode node) {
4646

4747
@Override
4848
public CmdIn createShellCmd(Job job, StepNode node) {
49-
// node envs has top priority;
50-
Vars<String> inputs = new StringVars()
51-
.merge(job.getContext())
52-
.merge(node.getEnvironments());
53-
54-
// create cmd based on plugin
5549
CmdIn cmd = new CmdIn(createId(job, node).toString(), CmdType.SHELL);
56-
cmd.setInputs(inputs);
50+
cmd.setInputs(job.getContext()); // yml env was in the job context
5751
cmd.setFlowId(job.getFlowId()); // default work dir is {agent dir}/{flow id}
5852
cmd.setDocker(node.getDocker());
5953

@@ -69,7 +63,7 @@ public CmdIn createShellCmd(Job job, StepNode node) {
6963
cmd.setAllowFailure(node.isAllowFailure());
7064
}
7165

72-
if (!isDockerEnabled(inputs)) {
66+
if (!isDockerEnabled(job.getContext())) {
7367
cmd.setDocker(null);
7468
}
7569

core/src/main/java/com/flowci/core/job/service/JobServiceImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ private void setupYaml(Flow flow, String yml, Job job) {
353353

354354
job.setCurrentPath(root.getPathAsString());
355355
job.setAgentSelector(root.getSelector());
356-
job.getContext().merge(root.getEnvironments());
356+
job.getContext().merge(root.getEnvironments(), false);
357357

358358
ymlManager.create(flow, job, yml);
359359
jobDao.save(job);

domain/src/main/java/com/flowci/domain/Vars.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,24 @@ public V get(String key, V defaultValue) {
6161
}
6262

6363
public Vars<V> merge(Vars<V> other) {
64+
return merge(other, true);
65+
}
66+
67+
public Vars<V> merge(Vars<V> other, boolean overwrite) {
6468
if (Objects.isNull(other)) {
6569
return this;
6670
}
6771

6872
for (Map.Entry<String, V> entry : other.entrySet()) {
69-
put(entry.getKey(), entry.getValue());
73+
String key = entry.getKey();
74+
75+
if (this.containsKey(key) && !overwrite) {
76+
continue;
77+
}
78+
79+
put(key, entry.getValue());
7080
}
81+
7182
return this;
7283
}
7384

0 commit comments

Comments
 (0)