cloudfoundry-community / slack-notification-resource

Concourse CI resource for sending notifications to Slack.
MIT License
75 stars 81 forks source link

Ability to specify notification color in slack #63

Open M0nsieurChat opened 5 years ago

M0nsieurChat commented 5 years ago

Hello !

First of all, thanks for your amazing work !

Would it be possible to introduce a new attribute color: so that we could specify which color would be applied to the text notification inside Slack ?

I think this is possible because our other slack integrations will apply different colors for different notifications statuses

screenshot from 2019-01-21 12-35-43 screenshot from 2019-01-21 12-35-28

Doing so could differentiate on_success and on_failure notifications and make more clear which builds failed and which builds succeed

Thanks,

jhunt commented 5 years ago

Definitely! Is that something you would be interested in working on / submitting a PR for?

M0nsieurChat commented 5 years ago

Looking at the slack documentation, it seems this "color" is only achievable through attachments : https://api.slack.com/docs/message-attachments

Fortunately, there is an attachments: parameter so I might be able to reproduce this without altering the container resource.

M0nsieurChat commented 5 years ago

This works :

  on_success:
    put: slack-notification
    params:
      text: "Build ${BUILD_PIPELINE_NAME}/${BUILD_JOB_NAME} #${BUILD_NAME} successful - ${ATC_EXTERNAL_URL}/teams/main/pipelines/${BUILD_PIPELINE_NAME}/jobs/${BUILD_JOB_NAME}/builds/${BUILD_NAME}"
      attachments:
        - text: "Success !"
          color: "#36a64f"

screenshot from 2019-01-21 18-28-17

One would want to use the ${text_interpolated} inside the text: attribute of the attachment but this would require some work on the out bash file : https://github.com/cloudfoundry-community/slack-notification-resource/blob/master/out#L134