jenkins上添加text parameter, 用脚本读取并存到配置文件中
来源:互联网 发布:软件可否申请专利 编辑:程序博客网 时间:2024/06/06 09:35
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, linesepfrom ConfigParser import ConfigParserfrom StringIO import StringIOfrom pdb import set_traceimport StringIOdefault_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 productcfg.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_configif custom_config:buf = StringIO.StringIO(custom_config)cfg.readfp(buf)return cfgdef 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 environwith open(cfg_file_path, 'w') as f:build_cfg(environ).write(f)passif __name__ == '__main__':main('temp.cfg')print 'creat-cfg-py'
1 0
- jenkins上添加text parameter, 用脚本读取并存到配置文件中
- python 网络上抓取数据处理并存入到Excel'中
- Fortan中读取数据到text文件
- 用nodejs读取文件并存入excel中
- c语言把文件中数据读取并存到数组中
- Pig脚本从Hive中load数据并存入到Hbase中
- java读取word中的表格并存入到mysql数据库中实例
- matlab将多个excel读取并存到一个excel的不同sheet中
- shell脚本读取配置文件
- shell脚本读取配置文件
- shell脚本读取配置文件
- bat脚本读取配置文件
- 从Excel中读取已知坐标 添加到百度地图上
- 用parameter添加数据
- Window form中App.config配置文件的添加和读取
- 用java将数据库表中内容读取出来并存入txt中
- 将sublime text添加到右键菜单中
- 将Sublime Text 3添加到右键菜单中
- SqlServer有关锁和内存使用的DMV
- iOS面向切面编程-AOP
- 在前端获取上传的excel文件内容
- 《The.Go.Programming.Language.2015.11.pdf》之map和结构体
- LeetCode 198. House Robber
- jenkins上添加text parameter, 用脚本读取并存到配置文件中
- 题目:判断101-200之间有多少个素数,并输出所有素数。
- Kendo UI开发教程:Kendo UI模板概述
- SQL视图
- 2016.11.11 js对象(RegExp 事件)
- C# ListView用法详解 很完整
- 使用SevenZipSharp压缩、解压文件
- jquery 两种方法设置disabled属性
- Exsi5.0在虚拟机中安装时提示Intel VT不支持解决办法