     (format "%s (Run %s)" pipeline-run stage-run)))
 
 
-(defn- previous-stage-trigger [{:keys [pipeline-name pipeline-run stage-name stage-run]} stages]
-  (when (= "1" stage-run)
-    (when-let [previous-stage (last (take-while #(not= stage-name (:name %)) stages))]
-      [{:job-name (job-name pipeline-name (:name previous-stage) (:name previous-stage))
-        :build-id (build-id pipeline-run (:counter previous-stage))}])))
+(defn- previous-stage-trigger [pipeline-name pipeline-run stage-name stages]
+  (when-let [previous-stage (last (take-while #(not= stage-name (:name %)) stages))]
+    [{:job-name (job-name pipeline-name (:name previous-stage) (:name previous-stage))
+      :build-id (build-id pipeline-run (:counter previous-stage))}]))
+
 
 (defn- pipeline-build-cause [{:keys [modifications material changed]}]
   (when (and changed (= "Pipeline" (:type material)))
-    (let [revision-tokens (str/split (:revision (first modifications)) #"/")]
-      {:pipeline-name (nth revision-tokens 0)
-       :pipeline-run (nth revision-tokens 1)
-       :stage-name (nth revision-tokens 2)
-       :stage-run (nth revision-tokens 3)})))
+    (let [revision-tokens (str/split (:revision (first modifications)) #"/")
+          pipeline-name (nth revision-tokens 0)
+          pipeline-run (nth revision-tokens 1)
+          stage-name (nth revision-tokens 2)
+          stage-run (nth revision-tokens 3)]
+      {:job-name (job-name pipeline-name stage-name stage-name)
+       :build-id (build-id pipeline-run stage-run)})))
 
-(defn- pipeline-material-triggers [{:keys [stage-name]} pipeline-instance stages]
-  (let [revisions (:material_revisions (:build_cause pipeline-instance))
-        triggers (keep pipeline-build-cause revisions)]
-    (when (= stage-name (:name (first stages)))
-      (map (fn [{:keys [pipeline-name pipeline-run stage-name stage-run]}]
-             {:job-name (job-name pipeline-name stage-name stage-name)
-              :build-id (build-id pipeline-run stage-run)})
-           triggers))))
+(defn- pipeline-material-triggers [pipeline-instance stages]
+  (let [revisions (:material_revisions (:build_cause pipeline-instance))]
+    (keep pipeline-build-cause revisions)))
 
-(defn build-triggers-for-stage-instance [pipeline-instance stage-instance]
+
+(defn- first-stage? [stage-name stages]
+  (= stage-name (:name (first stages))))
+
+(defn- rerun? [stage-run]
+  (not= "1" stage-run))
+
+(defn build-triggers-for-stage-instance [pipeline-instance {:keys [pipeline-name pipeline-run stage-name stage-run]}]
   (let [stages (:stages pipeline-instance)]
-    (seq (concat (previous-stage-trigger stage-instance stages)
-                 (pipeline-material-triggers stage-instance pipeline-instance stages)))))
+    (if (first-stage? stage-name stages)
+      (pipeline-material-triggers pipeline-instance stages)
+      (when-not (rerun? stage-run)
+        (previous-stage-trigger pipeline-name pipeline-run stage-name stages)))))
 
 
 

(defn inputs-for-stage-instance [pipeline-instance]
  (let [revisions (:material_revisions (:build_cause pipeline-instance))]
    (map revision->input revisions)))





                          :end end
                          :outcome outcome
                          :inputs inputs}
                   (not (empty? triggered-by)) (assoc :triggered-by triggered-by))})
       job-instances))
