Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save lbr88/7ac994caf41208917a38ad5a8e3360e6 to your computer and use it in GitHub Desktop.
Save lbr88/7ac994caf41208917a38ad5a8e3360e6 to your computer and use it in GitHub Desktop.
Rundeck executions cleanup
#!/bin/bash
# see related issue: https://github.com/rundeck/rundeck/issues/357
# import vars
source ~/.rd/rd.conf
# make sure rd & jq commands are in the PATH
which -- rd jq >/dev/null || exit 1
del_executions() {
local project=$1
while true; do
rd executions deletebulk --noninteractive -y -m ${RD_OPTION_BATCH:-20} --older ${RD_OPTION_OLDER_THAN:-1m} -s succeeded -p $project | while read line; do
echo $line
if [[ $line =~ "No executions found to delete" ]];then
exit 1
fi
done || break
sleep 1s
done
}
# delete executions for each project
for p in $(RD_FORMAT=json rd projects list | jq -r .[]); do
echo cleanup in: $p
del_executions $p
done
exit 0
@lbr88
Copy link
Author

lbr88 commented Jul 27, 2018

Sourcing a local file with the variables instead of having them in the script itself. And only deleting executions that has succeeded

@lbr88
Copy link
Author

lbr88 commented Jul 27, 2018

I found that it rd does not return >0 when there is nothing to delete so i'm looking for the string "No executions found to delete" in the output instead and then breaking the loop that way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment