fix(apps): Fix passing arguments and variables to shell apps.

This commit is contained in:
Shane Mc Cormack 2024-08-16 17:36:56 +01:00
parent cde8515fb1
commit c7191b01e2

View File

@ -173,26 +173,54 @@ func (t *LocalJob) getEnvironmentENV() (res []string, err error) {
// nolint: gocyclo // nolint: gocyclo
func (t *LocalJob) getShellArgs(username string, incomingVersion *string) (args []string, err error) { func (t *LocalJob) getShellArgs(username string, incomingVersion *string) (args []string, err error) {
//extraVars, err := t.getEnvironmentExtraVars(username, incomingVersion) extraVars, err := t.getEnvironmentExtraVars(username, incomingVersion)
if err != nil {
t.Log(err.Error())
t.Log("Error getting environment extra vars")
return
}
var templateExtraArgs []string
if t.Template.Arguments != nil {
err = json.Unmarshal([]byte(*t.Template.Arguments), &templateExtraArgs)
if err != nil {
t.Log("Invalid format of the template extra arguments, must be valid JSON")
return
}
}
var taskExtraArgs []string
if t.Template.AllowOverrideArgsInTask && t.Task.Arguments != nil {
err = json.Unmarshal([]byte(*t.Task.Arguments), &taskExtraArgs)
if err != nil {
t.Log("Invalid format of the TaskRunner extra arguments, must be valid JSON")
return
}
}
// Script to run
args = append(args, t.Template.Playbook) args = append(args, t.Template.Playbook)
//if err != nil { // Include Environment Secret Vars
// t.Log(err.Error()) for _, secret := range t.Environment.Secrets {
// t.Log("Could not remove command environment, if existant it will be passed to --extra-vars. This is not fatal but be aware of side effects") if secret.Type == db.EnvironmentSecretVar {
// return args = append(args, fmt.Sprintf("%s=%s", secret.Name, secret.Secret))
//} }
}
//for name, value := range extraVars { // Include extra args from template
// if name == "semaphore_vars" { args = append(args, templateExtraArgs...)
// continue
// } // Include ExtraVars and Survey Vars
// args = append(args, fmt.Sprintf("%s=%s", name, value)) for name, value := range extraVars {
//} if name != "semaphore_vars" {
// args = append(args, fmt.Sprintf("%s=%s", name, value))
//for _, secret := range t.Environment.Secrets { }
// args = append(args, fmt.Sprintf("%s=%s", secret.Name, secret.Secret)) }
//}
// Include extra args from task
args = append(args, taskExtraArgs...)
return return
} }