diff --git a/README.md b/README.md index a2259d4..1338a32 100644 --- a/README.md +++ b/README.md @@ -33,6 +33,9 @@ $ go get github.com/adnanh/webhook to get the latest version of the [webhook][w]. ### Using package manager +#### Snap store +[![Get it from the Snap Store](https://snapcraft.io/static/images/badges/en/snap-store-white.svg)](https://snapcraft.io/webhook) + #### Ubuntu If you are using Ubuntu linux (17.04 or later), you can install webhook using `sudo apt-get install webhook` which will install community packaged version. diff --git a/docs/Hook-Examples.md b/docs/Hook-Examples.md index b18abf7..f2cab8c 100644 --- a/docs/Hook-Examples.md +++ b/docs/Hook-Examples.md @@ -377,3 +377,50 @@ In order to leverage the Signing Key for addtional authentication/security you m ] ``` + +## Travis CI webhook +Travis sends webhooks as `payload=`, so the payload needs to be parsed as JSON. Here is an example to run on successful builds of the master branch. + +```json +[ + { + "id": "deploy", + "execute-command": "/root/my-server/deployment.sh", + "command-working-directory": "/root/my-server", + "parse-parameters-as-json": [ + { + "source": "payload", + "name": "payload" + } + ], + "trigger-rule": + { + "and": + [ + { + "match": + { + "type": "value", + "value": "passed", + "parameter": { + "name": "payload.state", + "source": "payload" + } + } + }, + { + "match": + { + "type": "value", + "value": "master", + "parameter": { + "name": "payload.branch", + "source": "payload" + } + } + } + ] + } + } +] +``` diff --git a/webhook.go b/webhook.go index ea914fe..10c8c61 100644 --- a/webhook.go +++ b/webhook.go @@ -10,6 +10,7 @@ import ( "net/url" "os" "os/exec" + "path/filepath" "strings" "time" @@ -336,6 +337,13 @@ func handleHook(h *hook.Hook, rid string, headers, query, payload *map[string]in // check the command exists cmdPath, err := exec.LookPath(h.ExecuteCommand) + if err != nil { + // give a last chance, maybe is a relative path + relativeToCwd := filepath.Join(h.CommandWorkingDirectory, h.ExecuteCommand) + // check the command exists + cmdPath, err = exec.LookPath(relativeToCwd) + } + if err != nil { log.Printf("unable to locate command: '%s'", h.ExecuteCommand)