Skip to content

Commit

Permalink
Don't fail in sad path where input version cannot be deduced, but war…
Browse files Browse the repository at this point in the history
…n instead
  • Loading branch information
cburgmer committed Feb 11, 2022
1 parent 4ebded2 commit 4e1b559
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/build_facts/concourse/builds.clj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
[api :as api]
[transform :as transform]]
[clj-yaml.core :as yaml]
[clojure.java.io :as io]))
[clojure.java.io :as io]
[clojure.tools.logging :as log]))

(defn config-for [concourse-target]
(let [flyrc (io/file (System/getProperty "user.home") ".flyrc")
Expand Down Expand Up @@ -42,12 +43,13 @@

(defn- triggering-build [resources {:keys [input-name from-previous-jobs versions-with-context]}]
(when-let [input-version (build->triggered-input-version resources input-name)]
(let [version-with-context (->> versions-with-context
(if-let [version-with-context (->> versions-with-context
(filter #(= input-version (:version %)))
first)
builds-with-input (concat @(:input-to version-with-context)
@(:output-of version-with-context))]
(map #(triggering-build-in-builds-with-same-resource-version % builds-with-input) from-previous-jobs))))
first)]
(let [builds-with-input (concat @(:input-to version-with-context)
@(:output-of version-with-context))]
(map #(triggering-build-in-builds-with-same-resource-version % builds-with-input) from-previous-jobs))
(log/warnf "No triggered-by information could be deduced as version history did not contain the relevant version %s" (prn-str input-version)))))

(defn- with-build-info [config inputs-and-versions {:keys [id] :as build}]
(let [plan (delay (api/build-plan config id))
Expand Down
23 changes: 23 additions & 0 deletions test/build_facts/concourse/builds_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -797,6 +797,29 @@
:first_occurrence false})
(some-plan 4)
(some-events 4))
(let [[[_, [build]]] (sut/concourse-builds {:base-url "http://concourse:8000"
:bearer-token "fake-token"
:team-name "my-team"})]
(is (nil? (:triggered-by build))))))

(testing "should fail gracefully if version cannot be found"
(fake/with-fake-routes-in-isolation (serve-up (valid-session)
(all-jobs (a-job "my-team" "my-pipeline" "my-job"
{:inputs [{:name :git :trigger true :passed ["previous-job"]}]})
(a-job "my-team" "my-pipeline" "previous-job"))
(some-builds "my-team" "my-pipeline" "my-job"
{:id 4
:name "42"
:status "aborted"
:start_time (unix-time-in-s 2016 1 1 10 0 0)
:end_time (unix-time-in-s 2016 1 1 10 0 1)})
(some-resources 4
{:name "git"
:version {:ref "abcd1234"}
:first_occurrence true})
(some-plan 4)
(some-events 4)
(some-resource-versions "my-team" "my-pipeline" "git"))
(let [[[_, [build]]] (sut/concourse-builds {:base-url "http://concourse:8000"
:bearer-token "fake-token"
:team-name "my-team"})]
Expand Down

0 comments on commit 4e1b559

Please sign in to comment.