diff --git a/db/Task.go b/db/Task.go index 4a33b4d6..ca2fccb3 100644 --- a/db/Task.go +++ b/db/Task.go @@ -1,6 +1,7 @@ package db import ( + "encoding/json" "fmt" "github.com/go-gorp/gorp/v3" "time" @@ -9,7 +10,7 @@ import ( "github.com/semaphoreui/semaphore/util" ) -type ShellTaskParams struct { +type DefaultTaskParams struct { } type TerraformTaskParams struct { @@ -70,7 +71,11 @@ type Task struct { } func (task *Task) GetParams(target interface{}) error { - return nil + content, err := json.Marshal(task.TaskParams) + if err != nil { + return err + } + return json.Unmarshal(content, target) } func (task *Task) PreInsert(gorp.SqlExecutor) error { @@ -124,7 +129,18 @@ func (task *Task) GetUrl() *string { } func (task *Task) ValidateNewTask(template Template) error { - return nil + + var params interface{} + switch template.App { + case AppAnsible: + params = &AnsibleTaskParams{} + case AppTerraform, AppTofu: + params = &TerraformTaskParams{} + default: + params = &DefaultTaskParams{} + } + + return task.GetParams(params) } func (task *TaskWithTpl) Fill(d Store) error { diff --git a/services/tasks/LocalJob.go b/services/tasks/LocalJob.go index e0704c0a..71cbb6d5 100644 --- a/services/tasks/LocalJob.go +++ b/services/tasks/LocalJob.go @@ -437,7 +437,7 @@ func (t *LocalJob) Run(username string, incomingVersion *string) (err error) { params = db.TerraformTaskParams{} default: args, err = t.getShellArgs(username, incomingVersion) - params = db.ShellTaskParams{} + params = db.DefaultTaskParams{} } if err != nil {