Skip to content

Instantly share code, notes, and snippets.

@qrkourier
Created April 2, 2024 22:05
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 qrkourier/185b69f91815ac71c24b8619a9045d8e to your computer and use it in GitHub Desktop.
Save qrkourier/185b69f91815ac71c24b8619a9045d8e to your computer and use it in GitHub Desktop.
Artifactory retention policy
(
set -euxopipefail
ARTIFACTORY_REPO='zitipax-(openziti-(rpm|deb)-test|fork-(rpm|deb)-stable)'
: DELETE="--quiet"
DELETE="--dry-run"
RETENTION_DAYS=30
declare -a ARTIFACTS=(ziti-edge-tunnel openziti{,-controller,-router} zrok{,-share})
if [[ $DELETE =~ quiet ]] && {
echo "WARNING: permanently deleting" >&2;
sleep 9;
}
for META in rpm.metadata.name deb.name;
do
for ARTIFACT in ${ARTIFACTS[@]};
do
while read;
do
jf rt search --include 'created;path' --props "${META}=${ARTIFACT}" "${REPLY}/*" \
| jq --arg OLDEST $(date --date "-${RETENTION_DAYS} days" -Is) '.[]|select(.created < $OLDEST)|.path' \
| xargs -rl jf rt del $DELETE;
done< <(
jf rt cl -sS /api/repositories \
| jq --raw-output --arg artifactory "${ARTIFACTORY_REPO}" '.[]|select(.key|match($artifactory))|.key'
)
done
done
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment