[英]How to override value which set in Groovy config to value from Jenkins build parameter
For now I have a config.properties
file and a singleton configuration object, which reads the file to a map and then puts all the system variables there as well. 现在,我有一个config.properties
文件和一个singleton配置对象,该对象将文件读取到映射,然后将所有系统变量也放置在该映射中。 So when I run my tests via Jenkins, job's parameters with the same name will override values, set in config.properties
file. 因此,当我通过Jenkins运行测试时,具有相同名称的job参数将覆盖在config.properties
文件中设置的值。
This is expected and correct behavior for me. 这是我的预期和正确行为。 But I'd like to keep all the configuration and build parameters in GebConfig.groovy
file. 但我想将所有配置和构建参数保留在GebConfig.groovy
文件中。
So two questions here: 所以这里有两个问题:
Now, if I need to get GebConfig property in my code, I use browser.getConfig().getRawConfig().get("contextPath")
. 现在,如果我需要在代码中获取GebConfig属性,则可以使用browser.getConfig().getRawConfig().get("contextPath")
。 Is it proper call or there is better way to get params from config in tests' code? 是正确的调用还是有更好的方法从测试代码中的config获取参数?
How to implement passing Jenkins job's parameters to Geb configuration? 如何实现将Jenkins作业的参数传递给Geb配置? I got only the idea to search for it in System.getenv()
first: 我只有一个主意是先在System.getenv()
搜索它:
public String getProperty(String name) { Map<String, String> systemEnv = System.getenv(); return systemEnv.get(name) ?: browser.config.rawConfig.get(name); }
All build tools accept -DvarName=varValue to pass properties into GebConfig. 所有构建工具都接受-DvarName = varValue来将属性传递到GebConfig中。 Gradle , Maven , and Ant . Gradle , Maven和Ant 。 So you'd pass that variable through in your Jenkins Build step 因此,您可以在Jenkins Build步骤中传递该变量
Edit: Below is in my GebConfig which handles default values vs passed in variables 编辑:下面是在我的GebConfig中,它处理默认值与传入变量
System.setProperty("geb.env.username", System.getProperty("geb.env.username", 'test'))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.