我是Jenkin Pipeline的新手。我们有基于Maven的selenium-java自动化框架。我正在创建一个Jenkin Pipeline groovy脚本来调用自动化框架。
在框架中,我们有config.properties文件,其中存储了应用程序url,用户名和密码。
config.properties:
Url = https://#########/login.jsp
用户名= #########
密码= #########
要求:我们需要将Application URL,Username和Password作为Jenkin参数,并相应地运行自动化套件。
问题:如何从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
}
}
}
感谢有关如何修复代码以实现所需结果的任何帮助
使用writeFile步骤写入文件。
以下示例写入和读取文件config.properties
pipeline {
agent any
stages{
stage("props file"){
steps{
script {
def props = """Url=https://#########/login.jsp
Username=########
Password=########"""
writeFile file: "config.properties", text: props
def str = readFile file: "config.properties"
echo str
}
}
}
}
}
更新:如果属性文件已经存在,则可以使用readProperties步骤加载属性。