stages:
  - stage: On_Failure
    jobs:
      - job: notify_mattermost
        variables:
          - group: certbot-common
        pool:
          vmImage: ubuntu-20.04
        steps:
          - bash: |
              set -e
              MESSAGE="\
              ---\n\
              ##### Azure Pipeline
              *Repo* $(Build.Repository.ID) - *Pipeline* $(Build.DefinitionName) #$(Build.BuildNumber) - *Branch/PR* $(Build.SourceBranchName)\n\
              :warning: __Pipeline has failed__: [Link to the build](https://dev.azure.com/$(Build.Repository.ID)/_build/results?buildId=$(Build.BuildId)&view=results)\n\n\
              ---"
              curl -i -X POST --data-urlencode "payload={\"text\":\"${MESSAGE}\"}" "$(MATTERMOST_URL)"
    condition: failed()
