diff --git a/cmd/tasks_run.go b/cmd/tasks_run.go index 7f61555f..b4672fce 100644 --- a/cmd/tasks_run.go +++ b/cmd/tasks_run.go @@ -41,7 +41,8 @@ var tasksPreRun = &cobra.Command{ fmt.Println("Executing Pre-rollout Tasks") err = runTasks(iterateTaskGenerator(true, runCleanTaskInEnvironment), lYAML.Tasks.Prerollout, lagoonConditionalEvaluationEnvironment) if err != nil { - return err + fmt.Println("Pre-rollout Tasks Failed with the following error: " + err.Error()) + os.Exit(1) } fmt.Println("Pre-rollout Tasks Complete") return nil @@ -62,7 +63,8 @@ var tasksPostRun = &cobra.Command{ fmt.Println("Executing Post-rollout Tasks") err = runTasks(iterateTaskGenerator(false, runCleanTaskInEnvironment), lYAML.Tasks.Postrollout, lagoonConditionalEvaluationEnvironment) if err != nil { - return err + fmt.Println("Post-rollout Tasks Failed with the following error: " + err.Error()) + os.Exit(1) } fmt.Println("Post-rollout Tasks Complete") return nil @@ -206,6 +208,7 @@ func runCleanTaskInEnvironment(incoming lagoon.Task) error { task.Service = incoming.Service task.Shell = incoming.Shell task.Container = incoming.Container + task.Name = incoming.Name err := lagoon.ExecuteTaskInEnvironment(task) return err } diff --git a/internal/lagoon/tasks.go b/internal/lagoon/tasks.go index d7a86e81..b53de3b7 100644 --- a/internal/lagoon/tasks.go +++ b/internal/lagoon/tasks.go @@ -105,7 +105,7 @@ func getConfig() (*rest.Config, error) { // ExecuteTaskInEnvironment . func ExecuteTaskInEnvironment(task Task) error { if debug { - fmt.Printf("Executing task '%v':'%v'", task.Name, task.Command) + fmt.Printf("Executing task '%v':'%v'\n", task.Name, task.Command) } command := make([]string, 0, 5) if task.Shell != "" { @@ -118,14 +118,18 @@ func ExecuteTaskInEnvironment(task Task) error { command = append(command, task.Command) stdout, stderr, err := ExecPod(task.Service, task.Namespace, command, false, task.Container) - if err == nil { - if len(stdout) > 0 { - fmt.Printf("*** Task STDOUT ***\n %v \n *** STDOUT Ends ***\n", stdout) - } - if len(stderr) > 0 { - fmt.Printf("*** Task STDERR ***\n %v \n *** STDERR Ends ***\n", stderr) - } + + if err != nil { + fmt.Printf("*** Task '%v' failed - STDOUT and STDERR follows ***\n", task.Name) } + + if len(stdout) > 0 { + fmt.Printf("*** Task STDOUT ***\n %v \n *** STDOUT Ends ***\n", stdout) + } + if len(stderr) > 0 { + fmt.Printf("*** Task STDERR ***\n %v \n *** STDERR Ends ***\n", stderr) + } + return err } @@ -266,7 +270,7 @@ func ExecPod( Tty: tty, }) if err != nil { - return "", "", fmt.Errorf("error in Stream: %v", err) + return stdout.String(), stderr.String(), fmt.Errorf("Error returned: %v", err) } return stdout.String(), stderr.String(), nil