Coder Social home page Coder Social logo

drone-plugins / drone-slack Goto Github PK

View Code? Open in Web Editor NEW
62.0 12.0 80.0 454 KB

Drone plugin for sending Slack notifications

Home Page: http://plugins.drone.io/drone-plugins/drone-slack

License: Apache License 2.0

Go 100.00%
drone drone-plugin

drone-slack's Introduction

drone-slack

Build Status Slack Join the discussion at https://community.harness.io Drone questions at https://stackoverflow.com Go Doc Go Report

Drone plugin for sending Slack notifications. For the usage information and a listing of the available options please take a look at the docs.

Build

Build the binary with the following commands:

go build

Docker

Build the Docker image with the following commands:

GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -a -tags netgo -o release/linux/amd64/drone-slack
docker build --rm -t plugins/slack .

Usage

Execute from the working directory:

docker run --rm \
  -e SLACK_WEBHOOK=https://hooks.slack.com/services/... \
  -e PLUGIN_CHANNEL=foo \
  -e PLUGIN_USERNAME=drone \
  -e DRONE_REPO_OWNER=octocat \
  -e DRONE_REPO_NAME=hello-world \
  -e DRONE_COMMIT_SHA=7fd1a60b01f91b314f59955a4e4d4e80d8edf11d \
  -e DRONE_COMMIT_BRANCH=master \
  -e DRONE_COMMIT_AUTHOR=octocat \
  -e [email protected] \
  -e DRONE_COMMIT_AUTHOR_AVATAR="https://avatars0.githubusercontent.com/u/583231?s=460&v=4" \
  -e DRONE_COMMIT_AUTHOR_NAME="The Octocat" \
  -e DRONE_BUILD_NUMBER=1 \
  -e DRONE_BUILD_STATUS=success \
  -e DRONE_BUILD_LINK=http://github.com/octocat/hello-world \
  -e DRONE_TAG=1.0.0 \
  plugins/slack

Please note the following new environment variables:

  • SLACK_ACCESS_TOKEN: The access token for Slack API authentication.
  • PLUGIN_CUSTOM_BLOCK: Custom blocks in JSON format to include in the Slack message.

Make sure to replace your_access_token with your actual Slack access token and adjust

If you provide an access token, it will use the Slack API to send the message. Otherwise, it will use the webhook.

Release Preparation

Run the changelog generator.

docker run -it --rm -v "$(pwd)":/usr/local/src/your-app githubchangeloggenerator/github-changelog-generator -u drone-plugins -p drone-slack -t <secret github token>

You can generate a token by logging into your GitHub account and going to Settings -> Personal access tokens.

Next we tag the PR's with the fixes or enhancements labels. If the PR does not fufil the requirements, do not add a label.

Before moving on make sure to update the version file version/version.go && version/version_test.go.

Run the changelog generator again with the future version according to semver.

docker run -it --rm -v "$(pwd)":/usr/local/src/your-app githubchangeloggenerator/github-changelog-generator -u drone-plugins -p drone-slack <secret token> --future-release v1.0.0

Create your pull request for the release. Get it merged then tag the release.

drone-slack's People

Contributors

appleboy avatar blacksails avatar bradrydzewski avatar christianruhstaller avatar compressed avatar daniel-ac-martin avatar donny-dont avatar eoinmcafee00 avatar fsouza avatar henribru avatar jackspirou avatar jjn2009 avatar juniper-sqsp avatar kzaitsev avatar mdalp avatar orlando avatar renovate-bot avatar renovate[bot] avatar tboerger avatar tonglil avatar wesleimp avatar zwpaper avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

drone-slack's Issues

{{ datetime }} => Evaluation error: Helper datetime called with argument 0 with type int64 but it should be float64

Hello,

I try to use datetime in my .drone.yml:

- name: slack
    image: plugins/slack
    settings:
      webhook:
        from_secret: slack-drone-webhook
      channel: alert-drone
      link_names: true
      template: >
        {{#success build.status}}โœ…{{else}}๐Ÿž{{/success}} Build #{{build.number}} of {{repo.name}}@{{build.tag}}

        ๐Ÿ“ `{{commit.message}}`
        ๐Ÿ™‡ {{commit.author}}

        ๐Ÿ• {{datetime build.started "02.01.2006 15:04" "Europe/Berlin"}}

        ๐ŸŒ {{build.link}}

but this produce the following error:

Screenshot from 2021-07-06 21-30-40

2021/07/06 19:22:25 Evaluation error: Helper datetime called with argument 0 with type int64 but it should be float64
Current node:
String{Value:'Europe/Berlin', Pos:207}

Any idea how to cast int64 to float64 in the template?

Thanks!

Getting the slack username to tag on an unsuccessful build

Hello! I'm using the slack plugin in my drone pipeline to notify my channel on successful and unsuccessful builds. I was thinking of tagging the user on an unsuccessful build and sending a message on the channel when someone breaks the build. I'm having trouble figuring out how to use the slack username of the committer in my pipeline. I have a script, which makes a call to the salck API to get the slack name associated with that email. But I dont know how to access the output of this script in my nect step (which is the notify step). I'm writing the output of the script to a file, which I was trying to read in the "notify" script, but seems like we cannot add custom commands in the notify step? Here is my pipeline:

workspace:
  base: /go
  path: src/github.comcast.com/viper-ace/psn-router
  
pipeline:
  build:
    pull: true
    privileged: true
    image: registry.vipertv.net/viper-linear-routing/viper-drone-ci:0.0.0
    volumes:
    - /var/run/docker.sock:/var/run/docker.sock
    commands:
      - make build
  find_user:
    privileged: true
    image: registry.vipertv.net/viper-linear-routing/viper-drone-ci:0.0.1
    volumes:
    - /var/run/docker.sock:/var/run/docker.sock
    commands:
    - export tag_user=`./slack_api_request.sh`
    - echo "$tag_user" > ./tag_user

  notify:
    image: plugins/slack
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
    channel: viper-leg-routing-ci
    link_names: true
    secrets: [ slack_webhook ]
    webhook: $SLACK_WEBHOOK
    template: >
      {{#failure build.status}}
        BUILD BROKEN! <@THIS IS WHERE I WOULD LIKE TO GET THE SLACK USERNAME>
      {{else}}
        YAY!! BUILD PASSED!
      {{/failure}}
    when:
      event: [ push, tag, deployment, pull_request ]
      status: [ success, failue ]

Any clue how to do this? :)

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Repository problems

These problems occurred while renovating this repository. View logs.

  • WARN: Found renovate config warnings

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

dockerfile
docker/Dockerfile.linux.amd64
docker/Dockerfile.linux.arm64
docker/Dockerfile.windows.1809
  • plugins/base windows-1809-amd64@sha256:a5493cfd5ef8326296121233e392437ca535dcf8097f15edafd727fcf2d43ed6
docker/Dockerfile.windows.ltsc2022
  • plugins/base windows-ltsc2022-amd64@sha256:0f90d5bceb432f1ee6f93cf44eed6a38c322834edd55df8a6648c9e6f15131f4
droneci
.drone.yml
  • golang 1.21
  • golang 1.21
  • golang 1.21
  • golang 1.21
  • golang 1.21
  • golang 1.21
  • golang 1.21
  • golang 1.21
  • golang 1.21
  • golang 1.21
gomod
go.mod
  • go 1.20
  • github.com/drone/drone-template-lib v1.0.0
  • github.com/joho/godotenv v1.5.1
  • github.com/slack-go/slack v0.12.2
  • github.com/urfave/cli v1.22.14
  • github.com/urfave/cli/v2 v2.25.7
  • gotest.tools/v3 v3.5.1

  • Check this box to trigger a request for Renovate to run again on this repository

How use plugin?

Hi.

If use plugin from pipeline:

pipeline:
  slack:
    image: plugins/slack
    webhook: url
    channel: dev

Build failed:

panic: runtime error: slice bounds out of range [recovered]
0s
2
	panic: runtime error: slice bounds out of range
0s
4
goroutine 1 [running]:
0s
5
panic(0x821140, 0xc82000a060)
0s
6
	/usr/local/go/src/runtime/panic.go:481 +0x3e6
0s
7
github.com/drone-plugins/drone-slack/vendor/github.com/urfave/cli.HandleAction.func1(0xc8200e9468)
0s
8
	/go/src/github.com/drone-plugins/drone-slack/vendor/github.com/urfave/cli/app.go:476 +0x417
0s
9
panic(0x821140, 0xc82000a060)
0s
10
	/usr/local/go/src/runtime/panic.go:443 +0x4e9
0s
11
main.message(0xc8200ea130, 0x9, 0xc8200ea150, 0xd, 0xc8200ea0e8, 0x6, 0xc8200ea17b, 0x3, 0x67, 0x0, ...)
0s
12
	/go/src/github.com/drone-plugins/drone-slack/plugin.go:92 +0x407
0s
13
main.Plugin.Exec(0xc8200ea130, 0x9, 0xc8200ea150, 0xd, 0xc8200ea0e8, 0x6, 0xc8200ea17b, 0x3, 0x67, 0x0, ...)
0s
14
	/go/src/github.com/drone-plugins/drone-slack/plugin.go:55 +0x7d
0s
15
main.run(0xc8200dcf00, 0x0, 0x0)
0s
16
	/go/src/github.com/drone-plugins/drone-slack/main.go:184 +0x91f
0s
17
reflect.Value.call(0x77f780, 0x96f8c8, 0x13, 0x8a8378, 0x4, 0xc8200e93c8, 0x1, 0x1, 0x0, 0x0, ...)
0s
18
	/usr/local/go/src/reflect/value.go:435 +0x120d
0s
19
reflect.Value.Call(0x77f780, 0x96f8c8, 0x13, 0xc8200e93c8, 0x1, 0x1, 0x0, 0x0, 0x0)
0s
20
	/usr/local/go/src/reflect/value.go:303 +0xb1
0s
21
github.com/drone-plugins/drone-slack/vendor/github.com/urfave/cli.HandleAction(0x77f780, 0x96f8c8, 0xc8200dcf00, 0x0, 0x0)
0s
22
	/go/src/github.com/drone-plugins/drone-slack/vendor/github.com/urfave/cli/app.go:485 +0x2ee
0s
23
github.com/drone-plugins/drone-slack/vendor/github.com/urfave/cli.(*App).Run(0xc820001080, 0xc82000a210, 0x1, 0x1, 0x0, 0x0)
0s
24
	/go/src/github.com/drone-plugins/drone-slack/vendor/github.com/urfave/cli/app.go:244 +0xb05
0s
25
main.main()
0s
26
	/go/src/github.com/drone-plugins/drone-slack/main.go:141 +0x1707

Need run docker container (docker run -d blablabla drone-slack) with env SLACK_WEBHOOK and use plugin from notify?

Add time-taken to slack-message.

Hi!
We're currently using travis but is trying out drone, one thing I miss from travis is the time-taken in the slack-message, IMO that would be a sensible default, is this something that others also would like?
In that case I might try to build it myself.

Check if the token is not empty

Currently the error message sounds a little bit bad if the token is not provided via secrets. We should print a proper error message if we don't have the webhook available.

Not compatible with 0.6?

Hey there!

I haven't worked with drone in a while, and now picked it up again, I took some of my 0.5 configs and turned them to 0.6, now my build are always reported as successful in slack, even though the build fails (also shows red in the web interface).

I tried with a template, but I got the same results, adding {{build.status}} to the template shows success.

Perhaps it is reporting the status of itself? (The "notify" step in the following image is the slack plugin)

screen shot 2017-05-05 at 17 06 49

Here is my config:

notify:
    image: plugins/slack:latest
    channel: ci
    secrets:
      - SLACK_WEBHOOK
    when:
      status: [ failure, success ]
    template: >
      {{#success build.status}}
        BOOM! build {{build.number}} succeeded (status: {{build.status}}). Good job.
      {{else}}
        NOPE! {{build.number}} failed. Fix me please...
      {{/success}}

Strip commit message

Please add either a strip helper for the template or strip the commit message by default. Maybe consider extracting first line of commit message as build.commit_title and rest as build.commit_description or so. Newlines can break slack markup.

datetime Evaluation error: argument 0 with type int64 but it should be float64

Great plugin - thanks a lot!

Minor:
http://plugins.drone.io/drone-plugins/drone-slack/
Issue:
"datetime
converts a unix timestamp to a date time string. Example {{datetime build.started}}"
But

  1. Should be e.g. started: {{datetime 1519654914.0 "Mon Jan _2 15:04:05 2006" "EET"}}
  2. "Evaluation error: Helper datetime called with argument 0 with type int64 but it should be float64"
    template.go - 90: func toDatetime(timestamp float64, layout, zone string) string
    main.go - 185: Started: c.Int64("build.started"),
    plugin.go - 29: Started int64

Thank you.

Notify failing with slack plugin

Pipeline failing in notify when the event is Pull request with following error
Post : unsupported protocol scheme ""

workspace:
  base: /go
  path: src/github.com/xxx/xxx

pipeline:
  backend:
    image: golang:1.8.3
    commands:
      - go get github.com/tools/godep
      - go get -d ./...
      - godep restore ./...
      - export GOBIN=$GOPATH/bin
      - go vet ./...
      - go install

  notify:
    image: plugins/slack
    secrets: [ slack_webhook ]
    when:
      status: [ success, failure ]
    template: >
      {{#success build.status}}
        {{repo.name}} ({{build.branch}}) <{{ build.link }}|{{ repo.owner }}/{{ repo.name }}#{{truncate build.commit 8}}> build succeeded on {{uppercasefirst build.event}}. Good job {{ build.author }}.
      {{else}}
        {{repo.name}} ({{build.branch}}) <{{ build.link }}|{{ repo.owner }}/{{ repo.name }}#{{truncate build.commit 8}}> build failed on {{uppercasefirst build.event}}. Fix me please {{ build.author }}.
      {{/success}}


Helper function datetime does not match documentation

The documentation page lists datetime as a helper with a single argument, e.g. {{datetime build.started}}, but the function expects 3 arguments:

Evaluation error: Helper 'datetime' called with wrong number of arguments, needed 3 but got 1

Looking at the source code in drone/drone-template-lib:template/helpers.go#L62, it looks like datetime should be called as, for example, {{ datetime build.started "15:04" "" }}. But build.started is an integer and datetime expects a float, resulting in the following error when called as previously exemplified:

Evaluation error: Helper datetime called with argument 0 with type int64 but it should be float64

It doesn't currently seem possible to pass a float value to datetime, so either a helper should be added to allow create converting integers to floats, or the datetime function should allow an integer to be passed in directly.

Post : unsupported protocol scheme ""

Hello, I have this lines in .drone.yml:

notify:
    image: plugins/slack
    webhook_url: https://hooks.slack.com/services/xxx/yyy/zzz
    channel: drone

and getting this in job:
screenshot_20170324172557

allow message color override in settings

I use an initial step in my pipeline to send a message about a build that has just been started

steps:
  - name: slack-init
    image: plugins/slack
    settings:
      webhook: https://xxxx
      channel: deploy-feed
      template: "build just started"

however the message color seems to depend on the build status, which at this point I guess drone assumes it being green.

https://github.com/drone-plugins/drone-slack/blob/master/plugin.go#L94

it would be nice being able to send this message as warning:

https://github.com/drone-plugins/drone-slack/blob/master/plugin.go#L161

I suspect the default case might never be reached.

Git commit message?

Hello,

is there any possibility to include the commit message in the notification? I was trying to find any examples or remarks on that without success.

Thank you very much for you work on the plugin!

Best,
Ben

Broken build on slack error

We getting broken build when notification couldn't be sent (slack server unavailable, for example)
I think that drone-slack plugin should return exit code 0 in that case, and maybe this behavior should be configurable

screenshot to make things clear
image

Notification of build start

Would be nice to have the option to send an optional notification when the build starts. Might not be a sensible default, but it would help us avoid the context switching in checking a browser tab if we are in a hurry.

Bad link to the build

Hi,

Here is my plugin call:

pipeline:
  slack:
    image: plugins/slack
    secrets: [slack_webhook]
    username: drone
    when:
      status: [failure]

And the docker-compose.yml that runs docker:

services:

#... Nginx reverse proxy configuration ...

drone-server:
    image: drone/drone:0.8
    volumes:
      - ${DRONE_DATA_DIR}:/var/lib/drone/
      - ./.drone-env.yml:/etc/drone-env.yml
    restart: always
    environment:
      - DRONE_OPEN=${DRONE_OPEN}
      - DRONE_ORGS=${DRONE_ORGS}
      - DRONE_ADMIN=${DRONE_ADMIN}
      - DRONE_HOST=${DRONE_HOST} #=https://ci.mycompany.com
      - DRONE_BITBUCKET=true
      - DRONE_BITBUCKET_CLIENT=${DRONE_BITBUCKET_CLIENT}
      - DRONE_BITBUCKET_SECRET=${DRONE_BITBUCKET_SECRET}
      - DRONE_SECRET=${DRONE_SECRET}
  drone-agent-one:
    image: drone/agent:0.8
    command: agent
    restart: always
    depends_on:
      - drone-server
    volumes:
      - ${DOCKER_HOST_SOCKET}:/var/run/docker.sock
    environment:
      - DRONE_SERVER=drone-server:${DRONE_AGENT_SERVER_PORT}
      - DRONE_SECRET=${DRONE_SECRET}

I get the notification on Slack, but when I click on the link, I land on http://drone-server:8000/mygroupname/myreponame/3 when I'd like to land on https://ci.mycompany.com/mygroupname/myreponame/3

As you can see in docker-compose.yml, my DRONE_HOST is defined. How is the link generated ? I don't master go very well ๐Ÿ˜‰

Documentation doesn't match drone website

It's been really frustrating for me, the documentation linked here doesn't match the drone plugin website: http://readme.drone.io/plugins/slack/ and it seems the one on the website DOES work.

image

This is what I'm seeing, I wanted to know where some of the components of the template came from (was hoping to see it in the source code) so that I could repurpose by (for example) having a link to the release on github or something.

[feature] Allow template to be read from a file

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.

Wrong branch name in notification for pull requests

When sending a notification for a pull request, the branch is displayed as being master instead of the name of the pull request.

For example I see: *success* org/repo#abcd1234 (master) by user

Instead of master I would expect to see something like pr-123 or pull/123

secrets doesn't work when PR

I set notify part of pipeline like this:

notify:
    image: plugins/slack
    secrets: [ slack_webhook ]
    username: Test_Drone
    when:
      status: [ success, failure ]

it works when push, but it fails when PR, the error is Post : unsupported protocol scheme ""

Did I missed something? Or it is a bug?

Support multiple channels

Adding support for multiple channels would be helpful.

For example it would be great to notify: #deployments, #logging so devs are able to see heads-up on what deployments are effecting logging - one use case im sure there are many more.

Explodes without commit SHA1

Drone 0.5.0+dev, running drone exec without --commit.sha= explodes:

[slack:L0:0s] panic: runtime error: slice bounds out of range [recovered]
[slack:L1:0s]   panic: runtime error: slice bounds out of range
[slack:L2:0s]
[slack:L3:0s] goroutine 1 [running]:
[slack:L4:0s] panic(0x81fc60, 0xc82000a050)
[slack:L5:0s]   /usr/local/go/src/runtime/panic.go:481 +0x3e6
[slack:L6:0s] github.com/drone-plugins/drone-slack/vendor/github.com/urfave/cli.HandleAction.func1(0xc8200d15e8)
[slack:L7:0s]   /go/src/github.com/drone-plugins/drone-slack/vendor/github.com/urfave/cli/app.go:476 +0x417
[slack:L8:0s] panic(0x81fc60, 0xc82000a050)
[slack:L9:0s]   /usr/local/go/src/runtime/panic.go:443 +0x4e9
[slack:L10:0s] main.message(0x0, 0x0, 0x0, 0x0, 0xc82000bf64, 0x4, 0x0, 0x0, 0x0, 0xc82000bfb0, ...)
[slack:L11:0s]  /go/src/github.com/drone-plugins/drone-slack/plugin.go:83 +0x407
[slack:L12:0s] main.Plugin.Exec(0x0, 0x0, 0x0, 0x0, 0xc82000bf64, 0x4, 0x0, 0x0, 0x0, 0xc82000bfb0, ...)
[slack:L13:0s]  /go/src/github.com/drone-plugins/drone-slack/plugin.go:46 +0x7d
[slack:L14:0s] main.run(0xc8200c4f00, 0x0, 0x0)
[slack:L15:0s]  /go/src/github.com/drone-plugins/drone-slack/main.go:152 +0x79c
[slack:L16:0s] reflect.Value.call(0x77e680, 0x96daa8, 0x13, 0x8a69f8, 0x4, 0xc8200d1548, 0x1, 0x1, 0x0, 0x0, ...)
[slack:L17:0s]  /usr/local/go/src/reflect/value.go:435 +0x120d
[slack:L18:0s] reflect.Value.Call(0x77e680, 0x96daa8, 0x13, 0xc8200d1548, 0x1, 0x1, 0x0, 0x0, 0x0)
[slack:L19:0s]  /usr/local/go/src/reflect/value.go:303 +0xb1
[slack:L20:0s] github.com/drone-plugins/drone-slack/vendor/github.com/urfave/cli.HandleAction(0x77e680, 0x96daa8, 0xc8200c4f00, 0x0, 0x0)
[slack:L21:0s]  /go/src/github.com/drone-plugins/drone-slack/vendor/github.com/urfave/cli/app.go:485 +0x2ee
[slack:L22:0s] github.com/drone-plugins/drone-slack/vendor/github.com/urfave/cli.(*App).Run(0xc820001080, 0xc82000a200, 0x1, 0x1, 0x0, 0x0)
[slack:L23:0s]  /go/src/github.com/drone-plugins/drone-slack/vendor/github.com/urfave/cli/app.go:244 +0xb05
[slack:L24:0s] main.main()
[slack:L25:0s]  /go/src/github.com/drone-plugins/drone-slack/main.go:116 +0x11d5

It works with --commit.sha=โ€ฆ. Probably error message should be better.

link-names update is missing in Config of main.go

As part of #67, the link_names has been updated to link-names in d853651. But the same update is missing in the config mapping:

		Config: Config{
			Webhook:   c.String("webhook"),
			Channel:   c.String("channel"),
			Recipient: c.String("recipient"),
			Username:  c.String("username"),
			Template:  c.String("template"),
			ImageURL:  c.String("image"),
			IconURL:   c.String("icon.url"),
			IconEmoji: c.String("icon.emoji"),
			LinkNames: c.Bool("link_names"),
		},

LinkNames: c.Bool("link_names") should've been LinkNames: c.Bool("link-names")

So currently the link-names parameter is not working.

Update to raymond 2.0.2

I just spent a good twenty minutes trying to figure out why my mustache/handlebars/raymond template wasn't working.

The result, in the end, was that I was trying to use raymond's #equal helper: https://github.com/aymerick/raymond#the-equal-helper

But since the vendored copy here is from mid 2015, that feature isn't available. Could we update to a release, like 2.0.2 from just a few days ago?

How do I use slack plugin within ssh pipeline

Roughly code structure.

kind: pipeline
type: ssh
name: default

server: 
    host: XXXX
    user: root
    ssh_key: 
        from_secret: ssh_key

steps: 
- name XXXX
...
...
...
- name: slack
  image: plugins/slack
  settings:
    webhook: XXXXXXXX
    channel: cicd
    template: > 
      {{#success build.status}} 
        *{{#success build.status}}โœ”{{ else }}โœ˜{{/success}} {{ uppercasefirst build.status }}*: <https://github.com/{{ repo.owner }}/{{ repo.name }}/pull/{{ build.pull }}|Pull Request #{{ build.pull }}>
      {{else}}
        *{{#success build.status}}โœ”{{ else }}โœ˜{{/success}} {{ uppercasefirst build.status }}: Build #{{ build.number }}* (type: `{{ build.event }}`)
      <{{ build.link }}|Visit build page โ†—>
      {{/success}}
      Commit: <https://github.com/{{ repo.owner }}/{{ repo.name }}/commit/{{ build.commit }}|{{ truncate build.commit 8 }}> 

      Branch: <https://github.com/{{ repo.owner }}/{{ repo.name }}/commits/{{ build.branch }}|{{ build.branch }}> 

      Author: {{ build.author }} 
  when:
    status:
      - success
      - failure

Expand environment variables on templates?

Hello hello,
I was playing around with drone deployments and custom parameters and found a use case where it would be useful to be able to use one of the custom parameters in the notification message, but that would require being able to expand environment variables, which is currently not supported.

Would a PR adding that feature be considered?

Thanks!

proxy support

The hosts that drone run's requires the use of proxies in order to communicate externally. I've setup the following .drone.yml file where the proxy environment variables are set as well as the configuration for the slack plugin. We have no issues using curl to post to the slack webhook while running from the drone host, so the proxy is working. Should this plugin support my use case?

environment:
HTTPS_PROXY: http://proxy:8080
HTTP_PROXY: http://proxy:8080
...

slack:
webhook_url: https://hooks.slack.com/services/XXX/YYY/ZZZ
channel: #build_health
username: drone
on_started: true
on_success: true
on_failure: true

Newlines not working in message template

Given this step:

    - name: repro for github issue
      image: plugins/slack
      settings:
        webhook:
          from_secret: slack_deploy_notifications_webhook
        channel: deploy-notifications
        template: >
          this is a line\n
          this should be a new line

The message that is displayed in slack is:

this is a line\n this should be a new line

Screen Shot 2020-10-23 at 12 33 02 PM

Expected result is:

this is a line
this is a new line

Changed payload format?

I have built the binary locally with the instructions from the Dockerfile, if I execute this:

./drone-slack <<EOF
{
    "repo" : {
        "owner": "foo",
        "name": "bar",
        "self_url": "http://my.drone.io/foo/bar"
    },
    "build" : {
        "status": "success",
        "number": 22,
        "started_at": 1421029603,
        "finished_at": 1421029813,
        "message": "Update the Readme",
        "commit": {
            "sha": "9f2849d5",
            "branch": "master",
            "author": {
                "login": "johnsmith",
                "author": "[email protected]"
            }
        }
    },
    "vargs": {
        "webhook_url": "https://hooks.slack.com/services/SNIP",
        "username": "drone", 
        "channel": "#testing"
    }
}
EOF

It results in this:

panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xb code=0x1 addr=0x8 pc=0x401bbe]

goroutine 1 [running]:
main.GetMessage(0xc820018100, 0xc820010600, 0x0, 0x0)
    /home/tboerger/Projects/golang/src/github.com/drone-plugins/drone-slack/main.go:59 +0x19e
main.main()
    /home/tboerger/Projects/golang/src/github.com/drone-plugins/drone-slack/main.go:41 +0x624

Sending attachment

This is rather a question. The forum is in read only mode so I decided to ask here.

Can we send a complicated message format like including attachment and buttons to slack?

Webhook as secret

I am unable to pass the webhook variable in using a drone secret. Is there a custom configuration or documentation explaining this?

I have tried the usual formats:

    webhook: $${SLACK_HOOK}
    webhook: $SLACK_HOOK
    secrets: [ SLACK_HOOK ]

etc.

found character that cannot start any token

.drone.yml

pipeline:
  ****SOME CODE****
  notify:
    image: plugins/slack
    when:
      event: push
      branch: master
      status: [ success, failure ]
    webhook: https://hooks.slack.com/services/T5KH9SURQ/V6W7U1N3C/vcVB1niHcyPVPcilmkGrDKgw
    channel: @user
    username: drone
    template: >
      {{#success build.status}}
        Deploy {{build.number}} is SUCCESS!
      {{else}}
        Deploy {{build.number}} is FAILED!
      {{/success}}

After push I see ERROR:
ERROR: yaml: line 69: found character that cannot start any token

Line 79 is

webhook: https://hooks.slack.com/services/T5KH9SURQ/V6W7U1N3C/vcVB1niHcyPVPcilmkGrDKgw

After delete notify from .drone.yml - all is ok.

build.author not resolving to expected username

I have the following pipeline:

  - name: notify
    image: plugins/slack
    settings:
      webhook:
        from_secret: slack_webhook_url
      link_names: true
      template: >
        {{#if build.pull }}
          *{{#success build.status}}โœ”{{ else }}โœ˜{{/success}} {{ uppercasefirst build.status }}*: <https://URL/{{ repo.owner }}/{{ repo.name }}/pulls/{{ build.pull }}|Pull Request #{{ build.pull }}>
        {{else}}
          *{{#success build.status}}โœ”{{ else }}โœ˜{{/success}} {{ uppercasefirst build.status }}: Build #{{ build.number }}* (type: `{{ build.event }}`)
        {{/if}}

        Commit: <https://URL/{{ repo.owner }}/{{ repo.name }}/commit/{{ build.commit }}|{{ truncate build.commit 8 }}>
        
        Branch: <https://URL/{{ repo.owner }}/{{ repo.name }}/commits/{{ build.branch }}|{{ build.branch }}>
        
        Author: <@{{ build.author }}>
        
        <{{ build.link }}|Visit build page โ†—>

However, in slack the author of the PR is always mentioned, rather than the author of the most recent commit. Is this intended behaviour? The documentation states that it should be git author for current commit.

Docs typo

I`ve used template function from docs (http://plugins.drone.io/drone-plugins/drone-slack/):

   template: >
     {{ #success build.status }}
       build {{ build.number }} succeeded. Good job.
     {{ else }}
       build {{ build.number }} failed. Fix me please.
     {{ /success }}

but raymond fails on this, should be without whitespace in success function block:

   template: >
     {{#success build.status}}
       build {{ build.number }} succeeded. Good job.
     {{ else }}
       build {{ build.number }} failed. Fix me please.
     {{/success}}

Only send notifications on if one of a set of specific steps fails

Drone exposes the failed steps in DRONE_FAILED_STEPS.

Using this the extension could provide a very simply way to only alert if certain steps fail.

  image: plugins/slack
  name: notify
  settings:
    webhook:
      from_secret: slack_webhook_url
    build_steps:
      - test
      - e2e-test
      - integration-test
  when:
    status:
    - failure

Commit message with quote ' converted to &apos;

The {{build.message}} variable seems to be parsed for HTML entities. Is there a way to escape/truncate this ?

Here is an example commit message:

Merge branch 'release/1.0.18'

You will receive this in Slack:

Merge branch &apos;release/1.0.18&apos;

Using the following config:

- name: notify
  image: plugins/slack
  settings:
    webhook: { from_secret: ... }
    channel: test
    template: |
      Build #{{build.number}} completed in {{since build.created}}.
      > {{build.message}}

Example

The Slack doc says the following characters are reserved as characters for formatting &, <, and >. Everything else should be parsed as is (literal) I think.

https://api.slack.com/reference/surfaces/formatting

Thank you for this awesome project btw! ๐Ÿš€

Drone <-> Slack integration errors after latest version released

Pulling the latest plugins/slack image triggers the following error:

time="2020-09-17T14:31:23Z" level=error msg="execution failed: could not create template message: Evaluation error: Helper since called with argument 0 with type time.Time but it should be int64\nCurrent node:\n\tPath{Original:'build.started', Pos:190}"

drone configuration section:

  • name: slack
    image: plugins/slack:latest
    settings:
    webhook:
    from_secret: slack_webhook
    channel: drone-notificiations
    template: >
    {{uppercase build.status}}

    Repo: *{{repo.name}}*
    
    Branch: *{{build.branch}}*
    
    Commit: *{{build.commit}}*
    
    Build Number: *{{build.number}}*
    
    Author: *{{build.author}}*
    
    Build duration: *{{since build.started}}*
    
    {{build.link}}
    

    when:
    status: [ success, failure ]

Reverting back to 1.3.0 fixes the issue

document template language

The docs page has a couple of sections with info on templates (template reference and template function reference), but they only give info on the extra features this plugin provides over the template engine being used. No where is the template language/engine used documented, which from https://github.com/drone-plugins/drone-slack/blob/master/template.go#L13 I gather to be handle bars.

I'd open a PR adding the one or 2 line blurb but could not find where the files are that get rendered on http://plugins.drone.io/drone-plugins/drone-slack/

Create a tag and push into my repository. Trigger slack notification, but got 'panic: runtime error: slice bounds out of range'

when i create tag and push:

git tag -a '1.0.0' -m '1.0.0'
git push origin 1.0.0

step config below:

- name: prenotify
  image: plugins/slack
  pull: if-not-exists
  failure: ignore
  detach: true
  settings:
    webhook: https://hooks.slack.com/services/Txxjfoi892SA
    channel: proj-cicd
    username: ${DRONE_COMMIT_AUTHOR}
    icon_url: https://unsplash.it/256/256/?random
    template: >
        Hi, I'm starting <{{build.link}}|build#{{build.number}}> at <https://git.pm.bwoilmarine.com/${DRONE_REPO}|{{repo.name}}> due to {{build.event}}. DO NOT repeat that again untill its completion.

error logs below:

panic: runtime error: slice bounds out of range

goroutine 1 [running]:
main.message(0xc00001e041, 0x1d, 0xc000016590, 0x8, 0xc0000161ea, 0x7, 0xc000016552, 0x3, 0x8, 0xc0000164a0, ...)
/drone/src/plugin.go:112 +0x240
main.Plugin.Exec(0xc00001e041, 0x1d, 0xc000016590, 0x8, 0xc0000161ea, 0x7, 0xc000016552, 0x3, 0x8, 0xc0000164a0, ...)
/drone/src/plugin.go:71 +0xb4
main.run(0xc0000dc9a0, 0xc0000dc9a0, 0xc0000bb42f)
/drone/src/main.go:223 +0xacf
github.com/urfave/cli.HandleAction(0x73b280, 0x7c3498, 0xc0000dc9a0, 0xc0000d0fc0, 0x0)
/go/pkg/mod/github.com/urfave/[email protected]/app.go:490 +0xc8
github.com/urfave/cli.(*App).Run(0xc0000d89c0, 0xc0000be190, 0x1, 0x1, 0x0, 0x0)
/go/pkg/mod/github.com/urfave/[email protected]/app.go:264 +0x59d
main.main()
/drone/src/main.go:175 +0x171d

if i commit, not tag, everything goes well. e.g:

git add .
git commit -m 'balabala'
git push

Docs are missing

The link in the README.md is wrong and I don't see a DOCS.md file anywhere.

Allow to customize fallback message

Message template applies to text field, but not fallback. Preferrably, allow to customize separately.

From the slack docs:

Please note that the fallback field is required, and is displayed whenever message attachments cannot be shown (ie. mobile notifications, desktop notifications, IRC).

support templates via text/template

I want to use a custom template, but I don't want to learn the raymond templating language that this plugin uses. Most Go developers should already be used to text/template, so it should be available as an option.

I would personally just use text/template directly, but I assume that's not an option, which is why I am suggesting supporting both.

Possibly related to #68 - /cc @mmlb

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.