zoukankan      html  css  js  c++  java
  • Jenkins自动部署GKfmc程序

    记录Jenkins自动部署GKfmc程序

    #!/usr/local/env python3
    # -*- coding:utf-8 -*-
    
    import psutil, shutil, os
    
    # 杀死进程
    def kill_process_name(process_name):
        pid_list = psutil.pids()
        for pid in pid_list:
            try:
                each_pro = psutil.Process(pid)
                if process_name.lower() in each_pro.name().lower():
                    # logger.info('find and kill {}'.format(process_name))
                    each_pro.terminate()
                    each_pro.wait(timeout=3)
    
            except psutil.NoSuchProcess as pid:
                pass
    
    # copy文件
    def copy_file(s_dir, d_dir):
        if os.path.exists(d_dir):
            shutil.rmtree(d_dir) # 删除zzinfo工作目录
        os.makedirs(d_dir)
        for root, dirs, files in os.walk(s_dir):
            for d in dirs:
                s_dir_name = os.path.join(root, d) # 列出workspace里面的子目录
                d_dir_name = s_dir_name.replace(s_dir, d_dir)
                if not os.path.exists(d_dir_name):
                    os.makedirs(d_dir_name) # 创建zzinfo里面的子目录
    
            for f in files:
                s_file_name = os.path.join(root, f) # 列出workspace里面的所有文件的绝对路径
                d_file_name = s_file_name.replace(s_dir, d_dir) # 列出目标文件的绝对路径
                shutil.copyfile(s_file_name, d_file_name)
    
    
    # main函数入口
    if __name__ == '__main__':
    
        os.environ['BUILD_ID'] = "dontKillMe"
    
        kill_process_name("gkfmc64.exe")
    
        # copy lib部分
        lib_s_dir = os.getenv("WORKSPACE") + r'lib'
        lib_d_dir = r"d:zzinfogkfmc64lib"
        copy_file(lib_s_dir, lib_d_dir)
    
        # copy bin部分
        bin_s_dir = os.getenv("WORKSPACE") + r'	argetclasses'
        bin_d_dir = r"d:zzinfogkfmc64in"
        copy_file(bin_s_dir, bin_d_dir)
    
        # 启动gkfmc64.exe
        os.popen(r"start /d d:zzinfoPTJYgkfmc64  gkfmc64.exe")
     
  • 相关阅读:
    Express 框架中 使用ejs
    Nodejs操作MongoDB数据库
    MongoDB基础操作
    node中的包、npm和模块
    background
    animation
    transition
    transform
    【SpringCloud】各种组件的更新情况
    【SpringCloud】版本选择
  • 原文地址:https://www.cnblogs.com/herui1991/p/12718149.html
Copyright © 2011-2022 走看看