@@ -3,7 +3,6 @@ package command
33import (
44 "context"
55 "fmt"
6- "os"
76
87 "github.com/spf13/cobra"
98 "github.com/veertuinc/anka-cloud-gitlab-executor/internal/ankacloud"
@@ -24,9 +23,9 @@ var cleanupCommand = &cobra.Command{
2423}
2524
2625func executeCleanup (ctx context.Context , env gitlab.Environment ) error {
27- log .SetOutput (os .Stdout )
26+ // log.SetOutput(os.Stdout) // prevents us from logging Println, etc
2827
29- log .Debugln ( "running cleanup stage" )
28+ log .Println ( " cleanup stage started for job: " , env . GitlabJobUrl )
3029
3130 if env .KeepAliveOnError && env .GitlabJobStatus == gitlab .JobStatusFailed {
3231 log .Colorln ("keeping VM alive on error" )
@@ -36,22 +35,25 @@ func executeCleanup(ctx context.Context, env gitlab.Environment) error {
3635 apiClientConfig := getAPIClientConfig (env )
3736 apiClient , err := ankacloud .NewAPIClient (apiClientConfig )
3837 if err != nil {
39- return fmt .Errorf ("failed to initialize API client with config +%v: %w" , apiClientConfig , err )
38+ log .Errorf ("cleanup: failed to initialize API client with config +%v: %v" , apiClientConfig , err )
39+ return fmt .Errorf ("cleanup: failed to initialize API client with config +%v: %v" , apiClientConfig , err )
4040 }
4141
4242 controller := ankacloud .NewController (apiClient )
4343
4444 instance , err := controller .GetInstanceByExternalId (ctx , env .GitlabJobUrl )
4545 if err != nil {
46- return fmt .Errorf ("failed to get instance by external id %q: %w" , env .GitlabJobUrl , err )
46+ log .Errorf ("cleanup: failed to get instance by external id %q: %v" , env .GitlabJobUrl , err )
47+ return fmt .Errorf ("cleanup: failed to get instance by external id %q: %v" , env .GitlabJobUrl , err )
4748 }
4849 log .Debugf ("instance id: %s\n " , instance .Id )
4950
5051 err = controller .TerminateInstance (ctx , ankacloud.TerminateInstanceRequest {
5152 Id : instance .Id ,
5253 })
5354 if err != nil {
54- return fmt .Errorf ("failed to terminate instance %q: %w" , instance .Id , err )
55+ log .Errorf ("cleanup: failed to terminate instance %q: %v" , instance .Id , err )
56+ return fmt .Errorf ("cleanup: failed to terminate instance %q: %v" , instance .Id , err )
5557 }
5658 log .Debugf ("Issuing termination request for instance %s\n " , instance .Id )
5759
0 commit comments