Last active
November 13, 2018 23:30
-
-
Save ashwanthkumar/9ba57d8cdfbcae956ba92a99ebf74bc4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 .`" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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