code: public function getJobsToRemove($projectPath, $keep = 1)
      {
          $currentJobs  = $this->strategy->getJobs($projectPath);
          $existingJobs = $this->getJobs($projectPath);
          $uniqList = array();
          $removes  = array();
          $ordered  = array();
  
          foreach ($currentJobs as $job) {
              $uniqList[] = $job->getUniq();
          }
  
          // Remove not existant image (old build configuration)
          foreach ($existingJobs as $job) {
              if (!in_array($job->getUniq(), $uniqList)) {
                  $removes[] = $job;
              } else {
                  $ordered[$job->getUniq()][$job->getCreated()->format('U')] = $job;
              }
          }
  
          // Remove old image
          foreach ($ordered as $jobs) {
              ksort($jobs);
              $keeped = count($jobs);
  
              while ($keeped > $keep) {
                  $removes[] = array_shift($jobs);
                  $keeped--;
              }
          }
  
          return $removes;
      }
docs: Get all jobs to remove given a project and how many versions to keep
  
  @param string $projectPath The project path
  @param int    $keep        Number of project to keep
  
  @return \Joli\JoliCi\Job[] A list of jobs to remove