diff --git a/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/processors/post/MsJSR223PostProcessor.java b/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/processors/post/MsJSR223PostProcessor.java index 7fbc96a05b..5a31690d1f 100644 --- a/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/processors/post/MsJSR223PostProcessor.java +++ b/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/processors/post/MsJSR223PostProcessor.java @@ -47,7 +47,10 @@ public class MsJSR223PostProcessor extends MsTestElement { return; } } - + // 复制脚本环境ID未改变情况下,使用父级环境ID + if (this.getParent() != null && !StringUtils.equals(this.getParent().getEnvironmentId(), this.getEnvironmentId())) { + this.setEnvironmentId(this.getParent().getEnvironmentId()); + } this.setEnvironmentId(ElementUtil.getScriptEnv(this.getEnvironmentId(), config, this.getProjectId())); TestElement processor = new BeanShellPostProcessor(); diff --git a/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/processors/pre/MsJSR223PreProcessor.java b/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/processors/pre/MsJSR223PreProcessor.java index 237d1dd770..25cc313990 100644 --- a/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/processors/pre/MsJSR223PreProcessor.java +++ b/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/processors/pre/MsJSR223PreProcessor.java @@ -48,6 +48,10 @@ public class MsJSR223PreProcessor extends MsTestElement { } } ScriptFilter.verify(this.getScriptLanguage(), this.getName(), script); + // 复制脚本环境ID未改变情况下,使用父级环境ID + if (this.getParent() != null && !StringUtils.equals(this.getParent().getEnvironmentId(), this.getEnvironmentId())) { + this.setEnvironmentId(this.getParent().getEnvironmentId()); + } this.setEnvironmentId(ElementUtil.getScriptEnv(this.getEnvironmentId(), config, this.getProjectId())); final HashTree jsr223PreTree = tree.add(getShellProcessor());