drone-plugins / drone-slack

Drone plugin for sending Slack notifications
http://plugins.drone.io/drone-plugins/drone-slack
Apache License 2.0
61 stars 80 forks source link

[feature] Allow template to be read from a file #122

Closed phil-davis closed 3 years ago

phil-davis commented 3 years ago

I want to be able to post information that is generated on-the-fly during the drone steps. For example, a test run might have some "interesting" result output, and I have parsed that and put it in a file. The script that parses the "interesting" test output can easily, if wanted, put existing template parameters into the text so that build-metadata will also be included.

1) allow the template to point to a file that contains the template text+metadata 2) if the file exists and is non-empty then post to the specified slack channel 3) if the file is empty, or does not exist, then do not post anything, and do not fail (maybe this can be an option - "do not fail on empty template")

Use case for (3): if the test output did not have anything "interesting" happen, then I don't want to report to slack, and I don't want the drone-slack step to fail.

phil-davis commented 3 years ago

I discovered that this can already be done. Put the text that you want into a local file. Then specify a reference to the file like:

                "template": "file:/someFolder/message.txt",

And that posts nicely to the slack channel.

phil-davis commented 3 years ago

I still need to work out how to avoid doing the reporting step if message.txt is empty or does not exist. In that case there is nothing to report, and I also do not want an error that "fails" the build.

sneak commented 1 year ago

@phil-davis it's unclear where one "specif[ies] a reference to the file" using this json syntax snippet you posted. my drone-slack is called thus:

    - name: notify
      image: plugins/slack
      settings:
        webhook:
          from_secret: SLACK_WEBHOOK_URL
      when:
        event: pull_request

I'm not sure where any json configuration goes.

sneak commented 1 year ago

Nevermind, I did it like this:

  - name: notify
    image: plugins/slack
    settings:
      template: "file:/drone/src/message.txt"
      webhook:
        from_secret: SLACK_WEBHOOK_URL
    when:
      event: pull_request

My previous steps write out the slack message in message.txt in the default working directory the tests run in.