Is there a way to delete job history programatically

1,120 views
Skip to first unread message

Evelyn Dibben

unread,
Apr 1, 2015, 5:48:26 PM4/1/15
to rundeck...@googlegroups.com
Alternatively is there a way to set how long job history is retained?

I swear I read something about this but I can't find the reference.  Thanks much.


Evelyn Dibben

unread,
Apr 1, 2015, 7:16:50 PM4/1/15
to rundeck...@googlegroups.com
Well I found the command:

TOKEN=mybiglongtoken
NODE=mynonde
URL="http://${NODE}:4440/api/12/executions/delete?ids=1471"  # You have to list the IDs
curl -H "X-RunDeck-Auth-Token:$TOKEN"  -X POST "$URL"

When I execute  curl I get this response:

<deleteExecutions requestCount='1' allsuccessful='false'>
  <successful count='0' />
  <failed count='1'>
    <execution id='1471' message='Unauthorized: Delete execution in project Rundeck' />
  </failed>



I've added this to /etc/rundeck/apitoken.aclpolicy

description: Allow API token to perform takeover schedule
context:
  application: 'rundeck'
for:
  resource:
    - equals:
        kind: job
      allow: [admin] # allow manage of schedule
    - equals:
        kind: project
      allow: [admin,delete_execution] # allow manage of schedule
by:
  group: api_token_group

Obviously something is still wrong with my ACL file but I'm not sure what.

Greg Schueler

unread,
Apr 1, 2015, 7:22:54 PM4/1/15
to rundeck...@googlegroups.com
Hi Evelyn,

you need to allow delete_execution for a specific project using “for: project:”

for:
  project:
    - match:
        name: '.*'
      allow: [delete_execution,read] # allow view and delete executions for all projects

--
You received this message because you are subscribed to the Google Groups "rundeck-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rundeck-discu...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Evelyn Dibben

unread,
Apr 2, 2015, 2:29:27 PM4/2/15
to rundeck...@googlegroups.com
The ACL policy stuff just confuses me, I need to spend more time on it :/

However, I did get this working,  the following snippet is from a bash script.  Pass in the PROJECT and RETENTION and the older jobs will be deleted.  I'm purging based on number of executions rather than by number of days - for my purpose this will suffice.

echo "Executing purge_job_history for project ${PROJECT} retention ${RETENTION}"
date

purged=0
URL="http://${NODE}:4440/api/2/project/${PROJECT}/jobs"
CURL_OUT=$(mktemp "/tmp/curl.out.XXXXX")
curl -H "X-RunDeck-Auth-Token:$TOKEN" -o $CURL_OUT -H "Content-Type: application/xml" -X POST "$URL" >/dev/null  2>&1

for JOB in $(xmlstarlet sel -t -m "/result/jobs/job" -m "@id" -v . -n ${CURL_OUT})
do
  # For each job get the oldest executions
  URL="http://${NODE}:4440/api/1/job/${JOB}/executions?offset=${RETENTION}"
  curl -H "X-RunDeck-Auth-Token:$TOKEN" -o $CURL_OUT -H "Content-Type: application/xml" -X GET "$URL" >/dev/null 2>&1
  for ID in $(xmlstarlet sel -t -m "/result/executions/execution" -m "@id" -v . -n ${CURL_OUT})
  do
    echo $ID
    URL="http://${NODE}:4440/api/12/executions/delete?ids=${ID}"
    curl -H "X-RunDeck-Auth-Token:$TOKEN" -o $CURL_OUT -X POST "$URL" >/dev/null 2>&1
    purged=$((purged+1))
  done
done

echo "Job executions purged:  $purged"


On Wednesday, April 1, 2015 at 3:48:26 PM UTC-6, Evelyn Dibben wrote:
Reply all
Reply to author
Forward
0 new messages