mirror of
https://github.com/adnanh/webhook.git
synced 2025-05-12 16:44:43 +00:00
Merge pull request #327 from dexpota/master
Fix issue with relative paths and command execution
This commit is contained in:
commit
002c332b68
3 changed files with 58 additions and 0 deletions
|
@ -33,6 +33,9 @@ $ go get github.com/adnanh/webhook
|
||||||
to get the latest version of the [webhook][w].
|
to get the latest version of the [webhook][w].
|
||||||
|
|
||||||
### Using package manager
|
### Using package manager
|
||||||
|
#### Snap store
|
||||||
|
[](https://snapcraft.io/webhook)
|
||||||
|
|
||||||
#### Ubuntu
|
#### 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.
|
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.
|
||||||
|
|
||||||
|
|
|
@ -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=<JSON_STRING>`, 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"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
```
|
||||||
|
|
|
@ -10,6 +10,7 @@ import (
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -336,6 +337,13 @@ func handleHook(h *hook.Hook, rid string, headers, query, payload *map[string]in
|
||||||
|
|
||||||
// check the command exists
|
// check the command exists
|
||||||
cmdPath, err := exec.LookPath(h.ExecuteCommand)
|
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 {
|
if err != nil {
|
||||||
log.Printf("unable to locate command: '%s'", h.ExecuteCommand)
|
log.Printf("unable to locate command: '%s'", h.ExecuteCommand)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue