Get Job Executions in Rundeck

Posted by in IT, Tutorial

Following the previous articles, we are now in position to query job executions. The query is done via API as well. As a job can have an arbitrary number of executions, it’s advisable to use pagination.

The code follows the same lines as the one in the previous entries:

This function builds the URL for the call and returns an XML string. Its parameters are:

  • server – the rundeck server
  • port – the rundeck server’s port
  • api_key – the api key for rundeck
  • job_id – one of the job IDs obtained by calling functions described here (or hardcoded)
  • page – the page we want to retrieve (offset is size * pages)
  • size – the page size (aka the max number of executions we want to retrieve at once)

We can go a step further with a wrapper:

…which would build a list of maximum MAXCOUNT * SIZE executions.

As the end objective is to remove old jobs, we need to retrieve the date for each execution. In effect we only need the execution ID and date:

In order to retrieve the executions with dates we’d need to call something like:

HTH,


A little experiment: If you find this post and ad below useful, please check the ad out :-)