jenkins上添加text parameter, 用脚本读取并存到配置文件中
2016-11-11 09:48
525 查看
1 功能需求
在jenkins上设置这些参数 即类似于设置系统变量 只不过设置name:custom_config / value : text parameter 而不是string parameter
自定义设置配置文件中一些session/value,可以不用再创建一个配置文件,以及在运行时载入这个配置文件( eg.... run.bat -C custom_config.cfg)
现直接在jenkins上设置text parameter , 再通过脚本读取text paramenter 并与已有的配置文件自动合并 运行
2 达到效果
最终生成的配置文件:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from os import environ, linesep
from ConfigParser import ConfigParser
from StringIO import StringIO
from pdb import set_trace
import StringIO
default_version = '0.0.0'
def add_val2section(cfg, section, name, value):
if value and value != default_version:
cfg.add_section(section)
cfg.set(section, name, value)
else:
print('[warning] {0}\'s version is not set in environment!'.format(section))
def build_sal_regression_cfg(env):
productname = env.get('SAL_product_name', 'sc')
sal_pattern_version = env.get('SAL_PATTERN_VERSION', default_version)
sal_build_version = env.get('SAL_BUILD_VERSION', default_version)
bep_build_version = env.get('BEP_BUILD_VERSION', default_version)
bep_pattern_version = env.get('BEP_PATTERN_VERSION', default_version)
custom_config = env.get('CUSTOM_CONFIG', '')
cfg_name = r'{0}.cfg'.format(productname)
cfg = ConfigParser()
# read the configuration of the product
cfg.read(cfg_name)
add_val2section(cfg, 'test_info', 'productname', productname)
add_val2section(cfg, 'pattern_sal', 'version', sal_pattern_version)
add_val2section(cfg, 'pattern_bep', 'version', bep_pattern_version)
add_val2section(cfg, 'build_win32_sal', 'version', sal_build_version)
add_val2section(cfg, 'build_win64_sal', 'version', sal_build_version)
add_val2section(cfg, 'build_win32_bep', 'version', bep_build_version)
add_val2section(cfg, 'build_win64_bep', 'version', bep_build_version)
# read custom_config
if custom_config:
buf = StringIO.StringIO(custom_config)
cfg.readfp(buf)
return cfg
def build_cfg(env):
test_name = env.get('SAL_test_name', 'sal_regression')
return build_sal_regression_cfg(env)
# raise Exception('SAL_test_name({0}) is not supported'.format(test_name))
def main(cfg_file_path):
#print environ
with open(cfg_file_path, 'w') as f:
build_cfg(environ).write(f)
pass
if __name__ == '__main__':
main('temp.cfg')
print 'creat-cfg-py'
在jenkins上设置这些参数 即类似于设置系统变量 只不过设置name:custom_config / value : text parameter 而不是string parameter
自定义设置配置文件中一些session/value,可以不用再创建一个配置文件,以及在运行时载入这个配置文件( eg.... run.bat -C custom_config.cfg)
现直接在jenkins上设置text parameter , 再通过脚本读取text paramenter 并与已有的配置文件自动合并 运行
2 达到效果
最终生成的配置文件:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from os import environ, linesep
from ConfigParser import ConfigParser
from StringIO import StringIO
from pdb import set_trace
import StringIO
default_version = '0.0.0'
def add_val2section(cfg, section, name, value):
if value and value != default_version:
cfg.add_section(section)
cfg.set(section, name, value)
else:
print('[warning] {0}\'s version is not set in environment!'.format(section))
def build_sal_regression_cfg(env):
productname = env.get('SAL_product_name', 'sc')
sal_pattern_version = env.get('SAL_PATTERN_VERSION', default_version)
sal_build_version = env.get('SAL_BUILD_VERSION', default_version)
bep_build_version = env.get('BEP_BUILD_VERSION', default_version)
bep_pattern_version = env.get('BEP_PATTERN_VERSION', default_version)
custom_config = env.get('CUSTOM_CONFIG', '')
cfg_name = r'{0}.cfg'.format(productname)
cfg = ConfigParser()
# read the configuration of the product
cfg.read(cfg_name)
add_val2section(cfg, 'test_info', 'productname', productname)
add_val2section(cfg, 'pattern_sal', 'version', sal_pattern_version)
add_val2section(cfg, 'pattern_bep', 'version', bep_pattern_version)
add_val2section(cfg, 'build_win32_sal', 'version', sal_build_version)
add_val2section(cfg, 'build_win64_sal', 'version', sal_build_version)
add_val2section(cfg, 'build_win32_bep', 'version', bep_build_version)
add_val2section(cfg, 'build_win64_bep', 'version', bep_build_version)
# read custom_config
if custom_config:
buf = StringIO.StringIO(custom_config)
cfg.readfp(buf)
return cfg
def build_cfg(env):
test_name = env.get('SAL_test_name', 'sal_regression')
return build_sal_regression_cfg(env)
# raise Exception('SAL_test_name({0}) is not supported'.format(test_name))
def main(cfg_file_path):
#print environ
with open(cfg_file_path, 'w') as f:
build_cfg(environ).write(f)
pass
if __name__ == '__main__':
main('temp.cfg')
print 'creat-cfg-py'
相关文章推荐
- 脚本引擎之----读取INI配置文件
- C 添加, 读取配置文件 函数
- 如何用shell脚本读取配置文件
- android应用面试宝典(下);用自定义组件控制循环组件使用bug还添加标志显示答案标志位;通过包名读取配置文件AndroidManifest.xml
- HTTP 错误 404.3 - Not Found 由于扩展配置问题而无法提供您请求的页面。如果该页面是脚本,请添加处理程序。如果应下载文件,请添加 MIME 映射。
- Linux shell读取配置文件使脚本更灵活(刚接触,求更好的办法)
- 自定义配置文件读取产生的“无法添加已属于该配置的 ConfigurationSection”异常解决办法
- 读取 jpa 的配置文件.添加自己的属性.
- HTTP 错误 404.3 - Not Found 由于扩展配置问题而无法提供您请求的页面。如果该页面是脚本,请添加处理程序。如果应下载文件,请添加 MIME 映射。
- shell脚本读取ini配置文件的值
- [11月29日的脚本] 向用户配置文件添加Window小工具的脚本 (PowerShell)
- shell脚本读取配置文件
- HTTP 错误 404.3 NOT FOUND 由于扩展配置问题而无法提供您请求的页面。如果该页面是脚本,请添加处理程序。如果应下载文件,请添加MIME映射。
- unix下使用TCL脚本读取配置文件
- shell脚本读取ini配置文件的值
- shell脚本读取配置文件
- windows2008下配置iis时出现错误“由于扩展配置问题而无法提供您请求的页面。如果该页面是脚本,请添加处理程序。如果应下载文件,请添加 MIME 映射。”
- c#配置文件appStrings配置节的读取、添加和修改
- 读取、添加、删除、修改配置文件 如(Web.config, App.config)
- 读取 为 指定 dll 添加的 配置文件App.config