Add slack notifier

This commit is contained in:
Teemu Patja 2017-03-23 17:42:30 +02:00
parent 54e50ec1fc
commit 9f19f4ac96
No known key found for this signature in database
GPG Key ID: F5B7035E6580FD4C
4 changed files with 26 additions and 5 deletions

View File

@ -12,7 +12,9 @@
[lambdacd-git "0.2.0"]
[compojure "1.5.2"]
[mount "0.1.11"]
[lambdacd-artifacts "0.2.1"]]
[lambdacd-artifacts "0.2.1"]
[clj-http "2.3.0"]
[org.clojure/data.json "0.2.6"]]
:plugins [[lein-environ "1.1.0"]]
:profiles {:uberjar {:aot :all}
:dev {:env {:home-dir "./cd-pipeline-home"}}

View File

@ -7,8 +7,6 @@
[lambdacd-git.core :as git]))
(def ^:const pipeline-def
`((either wait-for-git
manualtrigger/wait-for-manual-trigger)
@ -17,4 +15,5 @@
git/list-changes
build-uberjar
run-tests
deploy-uberjar)))
deploy-uberjar
slack-notify)))

View File

@ -0,0 +1,13 @@
(ns commiteth-pipeline.slack
(:require
[environ.core :refer [env]]
[clj-http.client :as client]
[clojure.data.json :as json]))
;; based on https://gist.github.com/mikebroberts/9604828
(defn slack-notify [text]
(let [webhook-url (env :slack-webhook-url)]
(client/post webhook-url {:form-params
{:payload (json/write-str
{:username "commiteth-cd-pipeline"
:text text})}})))

View File

@ -3,7 +3,8 @@
[lambdacd.steps.shell :as shell]
[lambdacd-git.core :as git]
[lambdacd-artifacts.core :as artifacts]
[clojure.tools.logging :as log]))
[clojure.tools.logging :as log]
[commiteth-pipeline.slack :as slack]))
(def repo-uri "https://github.com/status-im/commiteth.git")
@ -28,3 +29,9 @@
(shell/bash ctx
(:cwd args)
"sudo service commiteth stop && cp target/uberjar/commiteth.jar /opt/commiteth/commiteth.jar && sudo service commiteth start"))
(defn slack-notify [args ctx]
(let [msg (format "Deployed revision <a href=\"%s\">%s</a> to https://commiteth.com" (:revision args) (:revision args))]
(println "Sending slack notification")
(slack/slack-notify msg)
{:status :success}))