Add multiple conditional for slack notification?

Does notify accept multiple condition?

      notify:
        - slack:
            channels:
              - "#test"
            message: "Hurray! build was recently successful in main branch"
        if: build.state == "passed"

        - slack:
            channels:
              - "#test"
            message: "The most recent main branch build has failed, please take a look ."
        if: build.state == "failed"

Hi @Joe

You can do this sort of thing with multiple notifications to the same channel. However, conditionals (the parts in if:) are evaluated at the time the YAML is uploaded.
So the problem here is that for YAML to be uploaded to a build, it has to be running - which usually implies its passed or “running”. I suspect this might be where you are having troubles if any. When you upload the step that includes this notify, the build.state is probably “running” so you aren’t getting any notification.

I can think of a few ways around this. The first one is to use our default slack notifications which you can configure to send on passed or failed and includes a link to the build - you can’t configure the message exactly that way but perhaps it’ll still suit your needs.
Otherwise, you need to make use of, soft-failure and dynamic pipelines to upload a new step that can send the notification for you. We have an example at the bottom of this section in our docs: Triggering Notifications | Buildkite Documentation

steps:
  - command: exit -1
    soft_fail: true
    key: 'step1'
  - wait: ~
  - command: |
      if [ $$(buildkite-agent step get "outcome" --step "step1") == "soft_failed" ]; then
         cat <<- YAML | buildkite-agent pipeline upload 
         steps:
           - label: "Notify slack about soft failed step"
             command: echo "Notifying slack about the soft_failed step"
             notify:
               - slack:
                   channels:
                     - "#general"
                   message: "Step1 has soft failed."
      YAML
      fi