                                    pipeline-groups)]
     (println "Looking at pipeline groups" (map :name selected-pipeline-groups))
     (println "Syncing all builds starting from" (tf/unparse (:date-time tf/formatters) load-builds-from))
+    (when (some? accumulate-stages-for-pipelines)
+      (println "Aggregating jobs for stages of" accumulate-stages-for-pipelines))
 
     (println "Finding all builds for syncing...")
 
     (let [builds-to-be-synced (->> selected-pipeline-groups
                                  (mapcat stages-for-pipeline-group)
-                                 (mapcat (partial job-instances-for-stage load-builds-from))
+                                 (mapcat (partial job-instances-for-stage load-builds-from accumulate-stages-for-pipelines))
                                  (sort-by :scheduledDateTime))]
     (println (format "Found %s builds to be synced, starting" (count builds-to-be-synced)))
 

  (println "Go" go-url "-> buildviz" buildviz-url)

  (let [load-builds-from (get-start-date (:load-builds-from (:options args)))
        selected-pipeline-group-names (set (drop 1 (:arguments args)))
        pipeline-groups (get-pipeline-groups)
        selected-pipeline-groups (if (seq selected-pipeline-group-names)

(defn job-instances-for-stage-instance [{pipeline-run :pipeline_counter
                                         stage-run :counter
                                         jobs :jobs}]
  (map (fn [{id :id name :name scheduled-date :scheduled_date}]
         {:jobId id
          :jobName name
          :stageRun stage-run
          :pipelineRun pipeline-run
          :scheduledDateTime (tc/from-long scheduled-date)})
       jobs))

(defn job-instance-for-accumulated-stage-instance [{pipeline-run :pipeline_counter
                                                    stage-run :counter
                                                    jobs :jobs}]
  (let [job-instances (map (fn [{id :id name :name}]
                             {:jobId id :jobName name})
                           jobs)]
    {:jobId 0
     :jobName "accumulated"
     :stageRun stage-run
     :pipelineRun pipeline-run
     :scheduledDateTime (tc/from-long (apply min (map :scheduled_date jobs)))
     :jobs-for-accumulation job-instances}))

(defn fetch-job-instances-for-stage-instance [accumulate-stages-for-pipelines stage-name stage-instance]
  (if (contains? accumulate-stages-for-pipelines stage-name)
    (list (job-instance-for-accumulated-stage-instance stage-instance))
    (job-instances-for-stage-instance stage-instance)))

(defn get-stage-instances [pipeline stage-name offset]
  (let [stage-history (get-json "/api/stages/%s/%s/history/%s" pipeline stage-name offset)
