FWIW this is how I manage logs and artefacts for my company's use-case. We like to keep our console logs for a year, but remove other artefacts after 7 days.
It's just in bash and we trigger it via cron on Rockylinux 8 (RHEL8 compatible). These are destructive so use with caution; I'd strongly advise thoroughly testing these individually minus the destructive rm commands before using them in anger based on your configured filesystem in a sandbox. You should be able to take these as a reference and write something to closer match your own use-case. The shouts are just so when the script runs, it nicely outputs what's happening in ELK.
```
#!/bin/bash
SCRIPTNAME=$(basename "$0")
shout () {
echo "$SCRIPTNAME: $1"
}
shout "GoCD Artefacts cleardown script. I remove old artefacts."
# Remove artefacts older than 7 days but keep 'cruise-output' dir
shout "Removing Artefacts over 7 days old. Keeping GoCD Console logs.."
/usr/bin/find /godata/artifacts/pipelines -mindepth 6 -mtime -7 -prune -o -type d -name 'cruise-output' -prune -o -print0 | xargs -r0 rm -vrf
# Remove cruise-output by removing the artefact directory for pipeline runs older than 1 year
shout "Removing all artefacts older than one year old.."
/usr/bin/find /godata/artifacts/pipelines -mindepth 2 -maxdepth 2 -type d -mtime +365 | xargs -r rm -vrf
# Remove empty directories
shout "Removing empty directories.."
/usr/bin/find /godata/artifacts/pipelines -maxdepth 1 -type d -empty -exec rmdir -v {} \;
# Remove pipeline artefact cache dirs older than 7 days
shout "Removing pipeline cache older than 7 days old.."
/usr/bin/find /godata/artifacts/cache/artifacts/pipelines -maxdepth 2 -mindepth 2 -type d -mtime +7 | xargs -r rm -vrf
# Remove logs
shout "Removing any logs over 7 days old"
/usr/bin/find /godata/logs -type f -mtime +7 \( -name "*.log" -o -name "*.gz" \) -exec rm -vf {} \;
```