add sleep option

This commit is contained in:
Brad Rydzewski 2015-10-30 11:21:11 -07:00
parent 8b824ce040
commit eb3de49441
2 changed files with 10 additions and 1 deletions

View File

@ -28,6 +28,7 @@ deploy:
- bar.com - bar.com
user: root user: root
port: 22 port: 22
sleep: 5
commands: commands:
- echo hello - echo hello
- echo world - echo world
@ -35,6 +36,8 @@ deploy:
In the above example Drone executes the commands on multiple hosts sequentially. If the commands fail on a single host this plugin exits immediatly, and will not run your commands on the remaining hosts in the list. In the above example Drone executes the commands on multiple hosts sequentially. If the commands fail on a single host this plugin exits immediatly, and will not run your commands on the remaining hosts in the list.
The above example also uses the `sleep` parameter. The sleep parameter instructs Drone to sleep for N seconds between host executions.
## Keys ## Keys
The plugin authenticates to your server using a per-repository SSH key generated by Drone. You can find the public key in your repository settings in Drone. You will need to copy / paste this key into your `~/.ssh/authorized_keys` file on your remote machine. The plugin authenticates to your server using a per-repository SSH key generated by Drone. You can find the public key in your repository settings in Drone. You will need to copy / paste this key into your `~/.ssh/authorized_keys` file on your remote machine.

View File

@ -6,6 +6,7 @@ import (
"os" "os"
"strconv" "strconv"
"strings" "strings"
"time"
"github.com/drone/drone-plugin-go/plugin" "github.com/drone/drone-plugin-go/plugin"
"golang.org/x/crypto/ssh" "golang.org/x/crypto/ssh"
@ -18,6 +19,7 @@ type Params struct {
Login string `json:"user"` Login string `json:"user"`
Port int `json:"port"` Port int `json:"port"`
Host StrSlice `json:"host"` Host StrSlice `json:"host"`
Sleep int `json:"sleep"`
} }
func main() { func main() {
@ -27,11 +29,15 @@ func main() {
plugin.Param("vargs", &v) plugin.Param("vargs", &v)
plugin.MustParse() plugin.MustParse()
for _, host := range v.Host.Slice() { for i, host := range v.Host.Slice() {
err := run(w.Keys, v, host) err := run(w.Keys, v, host)
if err != nil { if err != nil {
os.Exit(1) os.Exit(1)
} }
if v.Sleep != 0 && i > v.Host.Len()-1 {
fmt.Printf("$ sleep %d\n", v.Sleep)
time.Sleep(time.Duration(v.Sleep) * time.Second)
}
} }
} }