zoukankan      html  css  js  c++  java
  • jenkins中配置参数化

    jenkins中配置参数化,并在python脚本接收参数实现参数化执行

    在自动化执行过程中,通过 argparse模块可以通过命令行进行传参,拿到参数并在脚本中进行处理。

    具体用法:

    parser = argparse.ArgumentParser(usage="it's usage tip.",description='help info.')
    parser.add_argument('--domain',type = str ,required = True,help='机构代码')
    parser.add_argument('--testcases',type = str ,default = 2,required = False,help='测试用例')
    args = parser.parse_args()
    return args

    在命令行中执行 python3 run.py --domain=domain --testcases=testcases,那么在jenkins中,进行参数配置:

    1.配置默认参数

    在配置时,需要选择"参数化构建过程",比如我是这样设置的:

     在需要使用这些参数的地方,这样使用:

     在linux或macos系统的化,使用"$标红的参数的名称"来获取,如果是Windows中使用 %标红的参数的名称%

     此时构建jenkins时就会出现参数化字段,带出默认值,且可以修改参数值

    2.配置选项

     执行构建时提供选择参数

     3.日期类参数

    首先需要安装插件:Date Parameter Plugin

     配置日期参数

     参数语法:

    # 语法
    You can create a 'default value' in one of two forms.
    1. Java LocalDate or LocalDateTime code style
     
    LocalDate.now();
    LocalDate.now().plusDays(1);
    LocalDate.now().plusDays(1).plusYears(2);
    LocalDate.now().minusDays(5).minusMonths(3).minusYears(2);
    LocalDateTime.now()
    LocalDateTime.now().minusHours(5).plusMinutes(10).minusSeconds(20);
    LocalDateTime.now().minusDays(5).plusYears(5).plusSeconds(50);
    2. LocalDate String (This case should match the format of 'dateFormat')
     
    20170501
    2017-05-01

    这样对于测试报告如果是根据日期保存的路径

       # 创建生成测试报告目录
        report_path = 'report/{}'.format(time.strftime('%Y%m%d'))
        if not os.path.exists(report_path):
            os.makedirs(report_path)
        # 将对应的testcase以列表形式存入
        args_list = [f'--alluredir={report_path}/data','--clean-alluredir']
        for testCase in testcases.split(','):
            args_list.insert(0,testCase)
        args_list.insert(0,'-vs')
        print(args_list)
        # 执行测试
        pytest.main(args_list)
        #生成测试报告
        os.system(f'allure generate {report_path}/data -o {report_path}/html --clean')

    则jenkins中报告配置

  • 相关阅读:
    linux -- 基于zookeeper搭建yarn的HA高可用集群
    Linux -- 之HDFS实现自动切换HA(全新HDFS)
    Hadoop格式化 From hu-hadoop1/192.168.11.11 to hu-hadoop2:8485 failed on connection exception: java.net.
    Directory /home/hdfs/name is in an inconsistent state: storage directory does not exist or is not a
    react学习01
    单页面应用(spa)引入百度地图(Cannot read property 'dc' of undefined)
    npm 发布包
    Vue学习-01
    echarts3.0使用总结
    webpack学习--创建一个webpack打包流程
  • 原文地址:https://www.cnblogs.com/wsy0202/p/15154195.html
Copyright © 2011-2022 走看看