Skip to content

Commit a40fba5

Browse files
author
Greg Dubicki
committed
Add CaptureCommandOutputOnError
to include stdout & stderror in failed executions, with docs.
1 parent 44d19e3 commit a40fba5

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

docs/Hook-Definition.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Hooks are defined as JSON objects. Please note that in order to be considered va
99
* `response-message` - specifies the string that will be returned to the hook initiator
1010
* `response-headers` - specifies the list of headers in format `{"name": "X-Example-Header", "value": "it works"}` that will be returned in HTTP response for the hook
1111
* `include-command-output-in-response` - boolean whether webhook should wait for the command to finish and return the raw output as a response to the hook initiator. If the command fails to execute or encounters any errors while executing the response will result in 500 Internal Server Error HTTP status code, otherwise the 200 OK status code will be returned.
12+
* `include-command-output-in-response-on-error` - boolean whether webhook should include command stdout & stderror as a response in failed executions. It only works if `include-command-output-in-response` is set to `true`.
1213
* `parse-parameters-as-json` - specifies the list of arguments that contain JSON strings. These parameters will be decoded by webhook and you can access them like regular objects in rules and `pass-arguments-to-command`.
1314
* `pass-arguments-to-command` - specifies the list of arguments that will be passed to the command. Check [Referencing request values page](Referencing-Request-Values) to see how to reference the values from the request. If you want to pass a static string value to your command you can specify it as
1415
`{ "source": "string", "name": "argumentvalue" }`

hook/hook.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,7 @@ type Hook struct {
384384
ResponseMessage string `json:"response-message,omitempty"`
385385
ResponseHeaders ResponseHeaders `json:"response-headers,omitempty"`
386386
CaptureCommandOutput bool `json:"include-command-output-in-response,omitempty"`
387+
CaptureCommandOutputOnError bool `json:"include-command-output-in-response-on-error,omitempty"`
387388
PassEnvironmentToCommand []Argument `json:"pass-environment-to-command,omitempty"`
388389
PassArgumentsToCommand []Argument `json:"pass-arguments-to-command,omitempty"`
389390
PassFileToCommand []Argument `json:"pass-file-to-command,omitempty"`

webhook.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,9 +282,13 @@ func hookHandler(w http.ResponseWriter, r *http.Request) {
282282
response, err := handleHook(matchedHook, rid, &headers, &query, &payload, &body)
283283

284284
if err != nil {
285-
w.Header().Set("Content-Type", "text/plain; charset=utf-8")
286285
w.WriteHeader(http.StatusInternalServerError)
287-
fmt.Fprintf(w, "Error occurred while executing the hook's command. Please check your logs for more details.")
286+
if matchedHook.CaptureCommandOutputOnError {
287+
fmt.Fprintf(w, response)
288+
} else {
289+
w.Header().Set("Content-Type", "text/plain; charset=utf-8")
290+
fmt.Fprintf(w, "Error occurred while executing the hook's command. Please check your logs for more details.")
291+
}
288292
} else {
289293
fmt.Fprintf(w, response)
290294
}

0 commit comments

Comments
 (0)