drone-plugins / drone-slack Goto Github PK
View Code? Open in Web Editor NEWDrone plugin for sending Slack notifications
Home Page: http://plugins.drone.io/drone-plugins/drone-slack
License: Apache License 2.0
Drone plugin for sending Slack notifications
Home Page: http://plugins.drone.io/drone-plugins/drone-slack
License: Apache License 2.0
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?
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?
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.
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.
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
It would be nice to have access to the $DRONE_DEPLOY_TO variable in order to include the environment being deployed to in notifications.
.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.
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.
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.
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
It should be nice to have an option to enable link_names when sending webhook request. This will enable tagging people or channels.
https://api.slack.com/incoming-webhooks
It is simple parameter in json that is sent.
I'd like not to notify a Slack channel when the build succeeds. Is it possible to configure it that way?
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?
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.
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
.
Slack allows you to set an icon_url
for each message: https://api.slack.com/methods/chat.postMessage
It would be awesome if drone would set it to a green checkmark/red X when the build succeeded or failed.
It would appear the setting icon_url
has no effect.
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
Thank you.
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).
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.
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!
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.
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.
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
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}}
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)
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}}
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
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.
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.
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}}
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
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 'release/1.0.18'
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}}
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! 🚀
It's cool that we can use {{build.message}}
to include the last commit message in the template but I'd like to see all commit messages since the last successful build but I'm not sure if this is even possible.
This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.
These problems occurred while renovating this repository. View logs.
These updates have all been created already. Click a checkbox below to force a retry/rebase of any.
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
.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
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
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/
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.
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.
The link in the README.md is wrong and I don't see a DOCS.md file anywhere.
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:
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!
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?
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.
template
to point to a file that contains the template text+metadataUse 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.
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 😉
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
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? :)
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
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
Is there a plan to add support for using drone secrets for slack webhook url?
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
Expected result is:
this is a line
this is a new line
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.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.