How can I send a notification in Discord when CI fails or is fixed?

Discord supports webhooks to send messages in a specific text channel. I want to use it send a notification when the build fail or is fixed. In Jenkins I used a plugin to call the webhook and placed the plugin call in the post field (the steps defined in post are always executed after all stages are done, even if one of them failed).

It looked like this:

  post {
    failure {
      script {
        gv = load "./.jenkins/script.groovy"
        gv.notifyDiscord(FAILED_STAGE)
      }
    }
    fixed {
      script {
        gv = load "./.jenkins/script.groovy"
        gv.notifyDiscord(FAILED_STAGE)
      }
    }
  }

Does Agola have something like post? I tried to do a task that depended on my last task, but when the the first task fails, the last one is skipped and the discord notification task is never called. Also, how can I get the run status and if it was an error, how can I get which task failed?

Our idea on creating notifications is by using dedicated tasks that will run after all the other tasks are finished (on any state) provided we have the run status available as environment variables, to be easily implemented we will need something like runservice: run task groups · Issue #5 · agola-io/agola · GitHub

Post tasks are something similar but will require an ad hoc implementation.

Ok. So it is not possible yet?

It’s already possible but could be improved, just define two tasks (failed and success notification) that depend on the final tasks of the run and that will be executed on different conditions (on_success for success notification; on_failure and maybe on_skipped for failed notification: Run Configuration Reference | Agola ).

Improvements could be done to make it easy defining these “post tasks” and there are many possibilities that should be examined to find an elastic solution that could fit multiple use cases (like runservice: run task groups · Issue #5 · agola-io/agola · GitHub)

1 Like