作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我试图通过单元测试设置环境变量,当我在本地计算机上运行代码时,它工作正常。
但是当我将它部署到 Jenkins 管道上时,它开始抛出异常。
异常:-
java.lang.NoSuchFieldException: theCaseInsensitiveEnvironment
代码片段:-
Class<?> processEnvironmentClass = Class.forName("java.lang.ProcessEnvironment");
Field theEnvironmentField = processEnvironmentClass.getDeclaredField("theEnvironment");
theEnvironmentField.setAccessible(true);
Map<String, String> env = (Map<String, String>) theEnvironmentField.get(null);
env.clear();
env.putAll(newenv);
Field theCaseInsensitiveEnvironmentField = processEnvironmentClass.getDeclaredField("theCaseInsensitiveEnvironment");
theCaseInsensitiveEnvironmentField.setAccessible(true);
Map<String, String> cienv = (Map<String, String>) theCaseInsensitiveEnvironmentField.get(null);
cienv.clear();
cienv.putAll(newenv);
最佳答案
您正在解决错误的问题。你的业务代码不应该直接依赖于环境变量,中间应该有一个隔离层。将您的输入与服务代码分离,您将不再需要模拟环境变量。
关于java - Jenkins 抛出 java.lang.NoSuchFieldException : theCaseInsensitiveEnvironment,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60994817/
我试图通过单元测试设置环境变量,当我在本地计算机上运行代码时,它工作正常。 但是当我将它部署到 Jenkins 管道上时,它开始抛出异常。 异常:- java.lang.NoSuchFieldExce
我尝试构建我的 gradle 项目,但出现以下错误:1:36 PM Gradle sync failed: Unable to make field private static final java
我是一名优秀的程序员,十分优秀!