From 803410e7640c47a60c8e9dee9a52c41315e2f1f7 Mon Sep 17 00:00:00 2001 From: Valentin P <7628998+w3st3ry@users.noreply.github.com> Date: Wed, 15 Jan 2020 10:33:46 +0100 Subject: [PATCH] Fix relative file path bug + rename file field (#68) Signed-off-by: Valentin Pichard <7628998+w3st3ry@users.noreply.github.com> --- engine/templates_tests/execScript.yaml | 2 +- pkg/plugins/builtin/script/README.md | 6 +++--- pkg/plugins/builtin/script/script.go | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/engine/templates_tests/execScript.yaml b/engine/templates_tests/execScript.yaml index d6564a9a..0af1ecf0 100644 --- a/engine/templates_tests/execScript.yaml +++ b/engine/templates_tests/execScript.yaml @@ -32,7 +32,7 @@ steps: # This file param is valid only in a testing context # In production, `file` will be prefixed by the utask.FScriptsFolder variable ("./scripts" by default) # You can specify your file's path relative to that location - file: "./scripts_tests/hello-world.sh" + file_path: "./scripts_tests/hello-world.sh" argv: - "{{.input.argv}}" timeout_seconds: "25" \ No newline at end of file diff --git a/pkg/plugins/builtin/script/README.md b/pkg/plugins/builtin/script/README.md index b2c6306b..c2baa1e9 100644 --- a/pkg/plugins/builtin/script/README.md +++ b/pkg/plugins/builtin/script/README.md @@ -12,7 +12,7 @@ Files must be located under scripts folder, you should set exec permissions (+x) |Fields|Description |---|--- -| `file` | file name under scripts folder +| `file_path` | file name under scripts folder | `argv` | a collection of script argv | `timeout` | timeout of the script execution | `stdin` | inject stdin in your script @@ -28,9 +28,9 @@ action: type: script configuration: # mandatory, string - # file field must be related to you scripts path (./scripts) + # file_path field must be related to you scripts path (./scripts) # and could modified /w `scripts-path` flag when you run binary - file: hello-world.sh + file_path: hello-world.sh # optional, a collection of string argv: - world diff --git a/pkg/plugins/builtin/script/script.go b/pkg/plugins/builtin/script/script.go index 4c811a84..73dd58e5 100644 --- a/pkg/plugins/builtin/script/script.go +++ b/pkg/plugins/builtin/script/script.go @@ -19,7 +19,7 @@ import ( // the script plugin execute scripts var ( - Plugin = taskplugin.New("script", "0.1", exec, + Plugin = taskplugin.New("script", "0.2", exec, taskplugin.WithConfig(validConfig, Config{}), ) ) @@ -35,7 +35,7 @@ type Metadata struct { // Config is the configuration needed to execute a script type Config struct { - File string `json:"file"` + File string `json:"file_path"` Argv []string `json:"argv,omitempty"` Timeout string `json:"timeout,omitempty"` Stdin string `json:"stdin,omitempty"` @@ -88,7 +88,7 @@ func exec(stepName string, config interface{}, ctx interface{}) (interface{}, in ctxe, cancel := context.WithTimeout(context.Background(), timeout) defer cancel() - cmd := gexec.CommandContext(ctxe, filepath.Join(utask.FScriptsFolder, cfg.File), cfg.Argv...) + cmd := gexec.CommandContext(ctxe, fmt.Sprintf("./%s", cfg.File), cfg.Argv...) cmd.Dir = utask.FScriptsFolder cmd.Stdin = strings.NewReader(cfg.Stdin)