使用gitlab-ci做自动化持续集成

2019-05-08  本文已影响0人  鱼豆腐爱好者协会会长

Python自动化测试脚本的gitlab-ci持续集成配置文件:

stages:

    - test

job_test:

    stage: test

    only:

        #只在定时任务触发时执行

        - schedules

    before_script:

        #确定执行python脚本的目标服务器是否有指定文件夹,如果没有则创建

        - ssh ${user}@${host} "if [ ! -d ${path_dir}code_dir ]; then mkdir -p ${path_dir}code_dir; fi"

        #在从gitlab仓库把代码复制到目标服务器之前,清理之前拷贝的数据

        - ssh ${user}@${host} "if [ -d ${path_dir}code_dir ]; then rm -rf ${path_dir}code_dir/*; fi"

        #从gitlab仓库复制代码到指定的目标服务器文件夹

        - scp -r * ${user}@${host}:${path_dir}code_dir

    when: on_success

    script:

        #执行目标服务器指定文件夹下的python脚本

        - ssh ${user}@${host} "python ${path_dir}code_dir/run_tests.py"

    tags:

        #使用的runner

        - dev

    #执行失败时,重试的次数

    retry: 2

上一篇 下一篇

猜你喜欢

热点阅读