Skip to content

Instantly share code, notes, and snippets.

@ashwanthkumar
Last active November 13, 2018 23:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ashwanthkumar/9ba57d8cdfbcae956ba92a99ebf74bc4 to your computer and use it in GitHub Desktop.
Save ashwanthkumar/9ba57d8cdfbcae956ba92a99ebf74bc4 to your computer and use it in GitHub Desktop.
#!/bin/bash
## This script get's the current working directory of an gocd-agent and
## deletes all the directories under pipelines/ except the ${GO_PIPELINE_NAME}.
## Since a stage is running on an agent, we've exclusive access over that agent
## it's safe to perform that delete.
CWD="$( cd "$( dirname "$0" )" && pwd )"
AGENT_PIPELINES_DIR=${CWD}/../
cd ${AGENT_PIPELINES_DIR}
echo "Current working directory: `pwd`"
echo "Current Size: `du -sh .`"
ls | grep -v ${GO_PIPELINE_NAME} | xargs -I% bash -c 'echo "Deleting %" && rm -rf %'
echo "Current size after delete: `du -sh .`"
format_version: 2
pipelines:
cleanup-gocd-agents-working-dir:
group: Ops
label_template: "cleanup-agents-${COUNT}"
lock_behavior: none
timer:
spec: "0 30 6 ? * *"
materials:
force:
git: https://gist.github.com/9ba57d8cdfbcae956ba92a99ebf74bc4.git
branch: master
auto_update: true
stages:
- cleanup:
fetch_materials: yes
clean_workspace: true
approval: manual
jobs:
cleanup:
run_instances: all
tasks:
- exec:
command: "/bin/bash"
arguments:
- cleanup_agent_pipelines_working_dir.sh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment