#!/bin/bash ## jenkins-workspace-clean-by-jobs.sh ## 循环寻找jobs任务文件夹 for file in /var/lib/jenkins/workspace/* do if [ -d "$file" ]; then job_name=`basename $file` if [[ ! -d "/var/lib/jenkins/jobs/$job_name" ]] && [[ ! $job_name =~ '@tmp' ]]; then echo "$job_name jobs下不存在workspace的这个任务文件夹,可以批量清理掉" rm -rf $file fi fi done # jobs文件夹有多少个任务 workspace_count=`ls -l /var/lib/jenkins/workspace | grep "^d" | wc -l` echo "workspace文件夹有 $workspace_count 个任务文件夹" jobs_count=`ls -l /var/lib/jenkins/jobs | grep "^d" | wc -l` echo "jobs文件夹有 $jobs_count 个任务文件夹"
标签:jobs,workspace,job,文件夹,file,jenkins From: https://www.cnblogs.com/fubinhnust/p/17317629.html