简体   繁体   English

如何使用Jenkins中的插件覆盖属性文件?

[英]How to override properties file using plugin in Jenkins?

In my Selenium-TestNG-Maven automation framework, I am have properties file for storing 'application-url'. 在我的Selenium-TestNG-Maven自动化框架中,我有用于存储“ application-url”的属性文件。 The Jenkins job is configured for this. 为此,Jenkins作业已配置。 I have to run this test suite on QA/Stage/Production server based on need. 我必须根据需要在质量检查/阶段/生产服务器上运行此测试套件。 But not sure how can I dynamically provide or override the 'application-url' property used in the code. 但不确定如何动态提供或覆盖代码中使用的“ application-url”属性。 (Environment Injector plugin? How?) (Environment Injector插件?如何?)

As per code, Selenium WebDriver instance in created, then java code reads the properties file and same URL is used by Selenium instance to open a webpage. 按照代码,创建Selenium WebDriver实例,然后用Java代码读取属性文件,Selenium实例使用相同的URL打开网页。

I dynamically provide URLs by using the choice parameter for my Jenkins job. 我通过为我的詹金斯工作使用choice参数动态提供URL。

First select this project is parameter as pictured below: 首先选择该项目的参数如下图:

Jenkins配置参数

Then select the Add Parameter > Choice Parameter as pictured below: 然后选择“添加参数”>“选择参数”,如下图所示:

选择参数

Then save. 然后保存。

Now when you are building you will be able to select the url to use for that particular build, like this: 现在,在构建时,您将能够选择用于该特定构建的URL,如下所示:

选择选择

And when you need to reference the url, you can pass it through to maven by using the $URL in the Maven Goals. 而且,当您需要引用该URL时,可以使用Maven目标中的$ URL将其传递给Maven。

ADDED: Here is an example of how I am using the choice parameter in the Maven goals 添加:这是我如何在Maven目标中使用choice参数的示例

Maven目标

I am passing the ${browserName} parameter that is defined using the Choice Parameter through maven which will be referenced using the system property "browser". 我通过maven传递了使用Choice Parameter定义的$ {browserName}参数,它将使用系统属性“ browser”进行引用。 So when I want to get the value in my code, I just use 因此,当我想在代码中获取值时,我只是使用

System.getProperty("browser");

And I am able to access that passed parameter. 而且我能够访问该传递的参数。

您可以配置您的jenkins,以从任何存储库(Github,SVN)中提取最新代码,并且在“ Execute Shell构建步骤中,可以编写一个shell script来实现相同的目的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM