【发布时间】:2020-06-05 03:43:09
【问题描述】:
我是 Jenkins Pipeline 的新手。我们有基于 maven 的 selenium-java 自动化框架。我正在创建一个 Jenkins Pipeline groovy 脚本来调用自动化框架。
在框架中,我们有 config.properties 文件,其中存储了 Application url 、用户名和密码。
config.properties:
网址=https://#########/login.jsp
用户名=########
密码=########
要求:我们需要将 Application URL 、 Username 和 Password 作为 Jenkins 参数,并相应地运行自动化套件。
问题:如何通过 Pipeline groovy 脚本在运行时更新 config.properties 文件?是否有可能在框架内创建一个 java 类来更新配置文件并从 groovy 脚本调用 java 类。
我试过下面的代码
node{
stage("props file"){
script {
def props = """Url=https://#########/login.jsp Username=########
Password=########"""
writeFile interpolate: true ,file: 'ui-automation/fw/config/config.properties', text: props
def str = readFile file: 'ui-automation-fw/config/config.properties'
echo str
}
}
}
感谢有关如何修复代码以实现所需结果的任何帮助
【问题讨论】:
-
请分享您的工作。
-
你好。解决方法是获取 maven 命令中的参数,但 pom.xml 中的变量除外。
标签: java selenium-webdriver jenkins-pipeline maven-2 jenkins-groovy