initial commit
This commit is contained in:
parent
790df28ae1
commit
fa69400d6c
1
.drone.sec
Normal file
1
.drone.sec
Normal file
|
@ -0,0 +1 @@
|
||||||
|
eyJhbGciOiJSU0EtT0FFUCIsImVuYyI6IkExMjhHQ00ifQ.ivt1r_hG7xhdImbwXIKSnGTkja9yPox9EjA58WhNXEvi7YHdFKsHx5LNcyH_o1W9LrUZEg0ag7QSEklpz900YdNX9HP6lpQ0yZso7Igo6i39nmvEihKypuIGWq8T3Vg7-ZH6UqwYuirxTKFU6lXcym-MLx7c8SEXdpnvUVO-Iq1X2ZGDLHjpi3h81qfsl5cvDdJadq9C2gCrqcHzXiiGLFMNVcB0zeIu8Q0osAZvmzMo9RoWZ3aAz8MH7JNNwbrUkZpO5t9wH0MqaaYbEKACWT6JP1XAUsEWv48CHQ1G2rtdNcjYMtJQbN78joTNkvDK6RkmBC5ZuCqfgeD_7Mi8OA.3hffaFSq-yxJWWaK._Ld4LgMpg4rn02CsVTTxrHbCUwmR_Z-JSkgAJgZg-U3Qz-EStA1G5G6oiOzunWMGTMgUDql4r8kigpC41GVbvv1_XGbUxKaribC_5p1_SBPZ8nZQ03zeKBp9-opW_gsImQkaqbG0L0GhHKVIaibhAsovo_92bb_gLu_W6oZgrWtATt1qgN0Q-8uRcfo-tuIzI0nU5vlQ4bmmNqfnT7QxGMIV-WhKZy5Rj004izO6bJojuAwuWq_WugWIhQbz-qpVnu0LlLwBbEVBaj6RsSULRHf_1UYVe_K3mmHxbcEpuRkiOU7yRJvwxsprQc0Hqge95QGKgwehZGF6SXfQstm4QnuV17_8PH3--cVLkIgzoZZ7yKWOYNqznn_ZX5jAFZdF5nRqyA.Ea5tn0QTKCKsjGoGP3tHlQ
|
22
DOCS.md
Normal file
22
DOCS.md
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
Use the Email plugin to send an email to a recipient list when a build completes. The following parameters are used to configuration the email plugin:
|
||||||
|
|
||||||
|
* **from** - sends email from this address
|
||||||
|
* **host** - smtp server host
|
||||||
|
* **port** - smtp server port (defaults to `587`)
|
||||||
|
* **username** - smtp server username
|
||||||
|
* **password** - smtp server password
|
||||||
|
* **recipient** - list of email recipients (defaults to commit email)
|
||||||
|
|
||||||
|
Same email configuration:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
notify:
|
||||||
|
email:
|
||||||
|
from: noreply@github.com
|
||||||
|
host: smtp.mailgun.org
|
||||||
|
port: 587
|
||||||
|
username: octocat
|
||||||
|
password: 12345
|
||||||
|
recipients:
|
||||||
|
- octocat@github.com
|
||||||
|
```
|
9
Dockerfile
Normal file
9
Dockerfile
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
# Docker image for Drone's email notification plugin
|
||||||
|
#
|
||||||
|
# CGO_ENABLED=0 go build -a -tags netgo
|
||||||
|
# docker build --rm=true -t plugins/drone-email .
|
||||||
|
|
||||||
|
FROM gliderlabs/alpine:3.1
|
||||||
|
RUN apk-install ca-certificates
|
||||||
|
ADD drone-email /bin/
|
||||||
|
ENTRYPOINT ["/bin/drone-email"]
|
41
README.md
Normal file
41
README.md
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
# drone-email
|
||||||
|
|
||||||
|
Drone plugin for sending email notifications.
|
||||||
|
|
||||||
|
## Overview
|
||||||
|
|
||||||
|
This plugin is responsible for sending build notifications via email:
|
||||||
|
|
||||||
|
```
|
||||||
|
./drone-email <<EOF
|
||||||
|
{
|
||||||
|
"repo" : {
|
||||||
|
"owner": "foo",
|
||||||
|
"name": "bar",
|
||||||
|
"full_name": "foo/bar"
|
||||||
|
},
|
||||||
|
"system": {
|
||||||
|
"link_url": "http://drone.mycompany.com"
|
||||||
|
},
|
||||||
|
"build" : {
|
||||||
|
"number": 22,
|
||||||
|
"status": "success",
|
||||||
|
"started_at": 1421029603,
|
||||||
|
"finished_at": 1421029813,
|
||||||
|
"commit": "64908ed2414b771554fda6508dd56a0c43766831",
|
||||||
|
"branch": "master",
|
||||||
|
"message": "Update the Readme",
|
||||||
|
"author": "johnsmith",
|
||||||
|
"author_email": "john.smith@gmail.com"
|
||||||
|
},
|
||||||
|
"vargs": {
|
||||||
|
"from": "noreply@foo.com",
|
||||||
|
"host": "smtp.mailgun.org",
|
||||||
|
"port": 587,
|
||||||
|
"username": "",
|
||||||
|
"password": "",
|
||||||
|
"recipients": ["octocat@github.com"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
EOF
|
||||||
|
```
|
32
main.go
32
main.go
|
@ -1,6 +1,7 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/drone/drone-go/drone"
|
"github.com/drone/drone-go/drone"
|
||||||
|
@ -11,7 +12,7 @@ type Email struct {
|
||||||
Recipients []string `json:"recipients"`
|
Recipients []string `json:"recipients"`
|
||||||
|
|
||||||
Host string `json:"host"`
|
Host string `json:"host"`
|
||||||
Port string `json:"port"`
|
Port int `json:"port"`
|
||||||
From string `json:"from"`
|
From string `json:"from"`
|
||||||
Username string `json:"username"`
|
Username string `json:"username"`
|
||||||
Password string `json:"password"`
|
Password string `json:"password"`
|
||||||
|
@ -34,14 +35,33 @@ func main() {
|
||||||
plugin.Param("build", &build)
|
plugin.Param("build", &build)
|
||||||
plugin.Param("repo", &repo)
|
plugin.Param("repo", &repo)
|
||||||
plugin.Param("vargs", &email)
|
plugin.Param("vargs", &email)
|
||||||
|
err := plugin.Parse()
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
err := Send(&Context{
|
// default to the commit email address
|
||||||
Email: email,
|
// if no email recipient list is provided
|
||||||
Build: build,
|
if len(email.Recipients) == 0 {
|
||||||
Repo: repo,
|
email.Recipients = []string{
|
||||||
|
build.Email,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// default smtp port
|
||||||
|
if email.Port == 0 {
|
||||||
|
email.Port = 587
|
||||||
|
}
|
||||||
|
|
||||||
|
err = Send(&Context{
|
||||||
|
Email: email,
|
||||||
|
Build: build,
|
||||||
|
Repo: repo,
|
||||||
|
System: system,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
println(err.Error())
|
fmt.Println(err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
"net/smtp"
|
"net/smtp"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/drone/drone-go/drone"
|
"github.com/drone/drone-go/drone"
|
||||||
|
@ -80,7 +81,7 @@ func send(subject, body string, c *Context) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
var auth smtp.Auth
|
var auth smtp.Auth
|
||||||
var addr = net.JoinHostPort(c.Email.Host, c.Email.Port)
|
var addr = net.JoinHostPort(c.Email.Host, strconv.Itoa(c.Email.Port))
|
||||||
|
|
||||||
// setup the authentication to the smtp server
|
// setup the authentication to the smtp server
|
||||||
// if the username and password are provided.
|
// if the username and password are provided.
|
||||||
|
|
Loading…
Reference in a new issue