简体   繁体   English

如何覆盖在Groovy配置中设置为Jenkins构建参数值的值

[英]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: 所以这里有两个问题:

  1. 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获取参数?

  2. 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 . GradleMavenAnt 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.

相关问题 Jenkins在构建步骤中覆盖参数值 - Jenkins override Parameter value on a Build Step 如何从 Jenkins 中的配置文件(groovy 脚本)中读取值? - How to read value from config file (groovy script) in Jenkins? 如何覆盖Jenkins参数化构建的默认值? - How to override the default value of a Jenkins parameterized build? jenkins-如何将值从bash传递到groovy? - jenkins - how to pass a value from bash to groovy? 如何在 Jenkins 文件中传递多选值参数(Groovy) - How to pass multi select value parameter in Jenkins file(Groovy) 使用groovy更改jenkins中的作业参数值 - Change job parameter value in jenkins using groovy Jenkins-cli的set-build-parameter命令不再起作用,如何在构建步骤之间修改构建参数的值? - Jenkins-cli's set-build-parameter command not working anymore, how to modify the value of a build parameter across build steps? Jenkins提升了构建参数值 - Jenkins Promoted Build Parameter Value Jenkins Build具有参数和身份验证,但没有参数值 - Jenkins Build with Parameter and authentication but no parameter value 詹金斯:如何从Groovy脚本中获取价值以用于下游项目? - Jenkins: How to get value from a Groovy Script to be used in a downstream project?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM