mirror of
https://github.com/semaphoreui/semaphore.git
synced 2025-01-20 07:19:20 +01:00
Merge pull request #2689 from semaphoreui/cli_args
refactor(be): add method getCLIArgs
This commit is contained in:
commit
1227cc212a
@ -185,22 +185,10 @@ func (t *LocalJob) getShellArgs(username string, incomingVersion *string) (args
|
||||
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
|
||||
}
|
||||
templateArgs, taskArgs, err := t.getCLIArgs()
|
||||
if err != nil {
|
||||
t.Log(err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
// Script to run
|
||||
@ -214,7 +202,7 @@ func (t *LocalJob) getShellArgs(username string, incomingVersion *string) (args
|
||||
}
|
||||
|
||||
// Include extra args from template
|
||||
args = append(args, templateExtraArgs...)
|
||||
args = append(args, templateArgs...)
|
||||
|
||||
// Include ExtraVars and Survey Vars
|
||||
for name, value := range extraVars {
|
||||
@ -224,7 +212,7 @@ func (t *LocalJob) getShellArgs(username string, incomingVersion *string) (args
|
||||
}
|
||||
|
||||
// Include extra args from task
|
||||
args = append(args, taskExtraArgs...)
|
||||
args = append(args, taskArgs...)
|
||||
|
||||
return
|
||||
}
|
||||
@ -259,6 +247,15 @@ func (t *LocalJob) getTerraformArgs(username string, incomingVersion *string) (a
|
||||
args = append(args, "-var", fmt.Sprintf("%s=%s", name, value))
|
||||
}
|
||||
|
||||
templateArgs, taskArgs, err := t.getCLIArgs()
|
||||
if err != nil {
|
||||
t.Log(err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
args = append(args, templateArgs...)
|
||||
args = append(args, taskArgs...)
|
||||
|
||||
for _, secret := range t.Environment.Secrets {
|
||||
if secret.Type != db.EnvironmentSecretVar {
|
||||
continue
|
||||
@ -381,31 +378,19 @@ func (t *LocalJob) getPlaybookArgs(username string, incomingVersion *string) (ar
|
||||
args = append(args, "--extra-vars", fmt.Sprintf("%s=%s", secret.Name, secret.Secret))
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
templateArgs, taskArgs, err := t.getCLIArgs()
|
||||
if err != nil {
|
||||
t.Log(err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
if t.Task.Limit != "" {
|
||||
t.Log("--limit=" + t.Task.Limit)
|
||||
taskExtraArgs = append(taskExtraArgs, "--limit="+t.Task.Limit)
|
||||
templateArgs = append(templateArgs, "--limit="+t.Task.Limit)
|
||||
}
|
||||
|
||||
args = append(args, templateExtraArgs...)
|
||||
args = append(args, taskExtraArgs...)
|
||||
args = append(args, templateArgs...)
|
||||
args = append(args, taskArgs...)
|
||||
args = append(args, playbookName)
|
||||
|
||||
if line, ok := inputMap[db.AccessKeyRoleAnsibleUser]; ok {
|
||||
@ -419,6 +404,27 @@ func (t *LocalJob) getPlaybookArgs(username string, incomingVersion *string) (ar
|
||||
return
|
||||
}
|
||||
|
||||
func (t *LocalJob) getCLIArgs() (templateArgs []string, taskArgs []string, err error) {
|
||||
|
||||
if t.Template.Arguments != nil {
|
||||
err = json.Unmarshal([]byte(*t.Template.Arguments), &templateArgs)
|
||||
if err != nil {
|
||||
err = fmt.Errorf("invalid format of the template extra arguments, must be valid JSON")
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if t.Template.AllowOverrideArgsInTask && t.Task.Arguments != nil {
|
||||
err = json.Unmarshal([]byte(*t.Task.Arguments), &taskArgs)
|
||||
if err != nil {
|
||||
err = fmt.Errorf("invalid format of the TaskRunner extra arguments, must be valid JSON")
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (t *LocalJob) getParams() (params interface{}, err error) {
|
||||
switch t.Template.App {
|
||||
case db.AppAnsible:
|
||||
@ -641,7 +647,7 @@ func (t *LocalJob) checkoutRepository() error {
|
||||
func (t *LocalJob) installVaultKeyFiles() (err error) {
|
||||
t.vaultFileInstallations = make(map[string]db.AccessKeyInstallation)
|
||||
|
||||
if t.Template.Vaults == nil || len(t.Template.Vaults) == 0 {
|
||||
if len(t.Template.Vaults) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user