zoukankan      html  css  js  c++  java
  • 空间清理jenkins,linux清理空间

    linux 空间清理

    #发现有大量刚刚删除文件的进程存在,kill掉进程(或者重启进程)   OK
    lsof | grep deleted
    
    
    #循环检测发现大目录及其内的文件
    
    du -h --max-depth=1 | sort  -gr
    
    
    
    
    

    获取大文件

    到jenkins的家目录

    find . -type f   -size +100M
    du -ah --max-depth=1
    find . -type f   -size +100M  | wc  -l
    find . -type f   -size +100M  -exec  rm -rf {} ;
    
    
    du -sh .[!.]* * | sort -hr  #查看隐藏文件
    
    find . -type f -size +800M  -print0 | xargs -0 du -h | sort -nr
    du -hm --max-depth=2 | sort -nr | head -12  
    du -h --max-depth=1
    
    
    
    
    #######
    ###删除操作
    在jenkins工作路径下/var/lib/jenkins
    find . -type f   -size +200M   -name *.jar    -exec  rm -rf {} ;
    
    
    

    构建工作区清理

    插件 Workspace Cleanup Plugin
    样例配置:
    构建前清理

    构建后操作:

    workspace 与job

    构建工作区(workspace)

    每一个构建(build)都需要一个workspace 目录作为构建的工作区,执行job配置中指定的任务
    默认情况下,构建工作区workspace是不会自动清理的,也就是说每一个job的build结束后,workspace被遗留在master或者slave对应的工作区目录下,Jenkins的本意是为下次构建复用工作区目录,这样一些代码下载,编译等可以加速
    可用Workspace Cleanup Plugin 清理

    job 中保存的是项目是在 jenkins 上的配置、日志、构建结果等
    workspace 就是工作目录,一般就是 Down 下来的源代码目录(网页打开的显示工作目录)

    清理删除job后的workspace

    具体思路是:

    遍历jenkins节点的workspace,根据路径解析获得jenkins job name
    如果该job不存在(通过python jenkinsapi实现),则删除相应的workspace
    暂不考虑自定义的workspace
    需要在jenkins每个节点上进行处理(可以在jenkins上创建job,将job绑定到相应slave上;也可以在相应slave上直接运行脚本)

    
    # -*- coding: utf-8 -*-
    import os
    import shutil
    import logging
     
    from jenkinsapi.jenkins import Jenkins
     
    logging.basicConfig(level=logging.INFO)
    logger = logging.getLogger(__file__)
     
     
    def get_jenkins_instance():
        jenkins_url = "http://jenkins.example.com"
        jenkins_username = "username"
        jenkins_password = "password"
        return Jenkins(jenkins_url, username=jenkins_username, password=jenkins_password)
     
     
    def clean_workspace():
        jenkins_instance = get_jenkins_instance()
     
        jenkins_workspace_path = "/opt/JENKINS_HOME/workspace/"
     
        for dirpath, dirnames, filenames in os.walk(jenkins_workspace_path):
            if dirpath == jenkins_workspace_path:
                for dirname in dirnames:
                    jenkins_job_name = dirname
                    # 如果job被删除,则清理相应的workspace
                    if not jenkins_instance.has_job(jenkins_job_name):
                        logger.info("removing workspace dir of job:%s" % dirname)
                        shutil.rmtree(os.path.join(dirpath, dirname))
     
     
    if __name__ == "__main__":
        clean_workspace()
    
    

    未测试:来自 https://blog.csdn.net/weixin_34034261/article/details/91766530

  • 相关阅读:
    LeetCode "Super Ugly Number" !
    LeetCode "Count of Smaller Number After Self"
    LeetCode "Binary Tree Vertical Order"
    LeetCode "Sparse Matrix Multiplication"
    LeetCode "Minimum Height Tree" !!
    HackerRank "The Indian Job"
    HackerRank "Poisonous Plants"
    HackerRank "Kundu and Tree" !!
    LeetCode "Best Time to Buy and Sell Stock with Cooldown" !
    HackerRank "AND xor OR"
  • 原文地址:https://www.cnblogs.com/g2thend/p/12403450.html
Copyright © 2011-2022 走看看