-
Notifications
You must be signed in to change notification settings - Fork 84
Expand file tree
/
Copy pathstep_write_worker_info.go
More file actions
56 lines (48 loc) · 2.01 KB
/
step_write_worker_info.go
File metadata and controls
56 lines (48 loc) · 2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package worker
import (
gocontext "context"
"fmt"
"strings"
"github.com/mitchellh/multistep"
"github.com/travis-ci/worker/backend"
"github.com/travis-ci/worker/context"
"go.opencensus.io/trace"
)
type stepWriteWorkerInfo struct {
}
func (s *stepWriteWorkerInfo) Run(state multistep.StateBag) multistep.StepAction {
logWriter := state.Get("logWriter").(LogWriter)
buildJob := state.Get("buildJob").(Job)
usedCustomImageId := state.Get("usedCustomImageId").(int)
usedCustomImageName := state.Get("usedCustomImageName").(string)
instance := state.Get("instance").(backend.Instance)
ctx := state.Get("ctx").(gocontext.Context)
_, span := trace.StartSpan(ctx, "WriteWorkerInfo.Run")
defer span.End()
if hostname, ok := state.Get("hostname").(string); ok && hostname != "" {
_, _ = writeFold(logWriter, "worker_info", []byte(strings.Join([]string{
"\033[33;1mWorker information\033[0m",
fmt.Sprintf("hostname: %s", hostname),
fmt.Sprintf("version: %s %s", VersionString, RevisionURLString),
fmt.Sprintf("instance: %s %s (via %s)", instance.ID(), instance.ImageName(), buildJob.Name()),
fmt.Sprintf("startup: %v", instance.StartupDuration()),
}, "\n")))
if usedCustomImageId != 0 {
writeSingleLine(logWriter, []byte(strings.Join([]string{
fmt.Sprintf("Using custom build environment image %s %s. See <link to the documentation>.", usedCustomImageName, instance.ImageName()),
}, "\n")))
}
if usedCustomImageId == 0 && usedCustomImageName != "" {
msg := fmt.Sprintf("Cannot find custom build environment identifier %s under the account managing this repository in Travis.\n", usedCustomImageName)
logWriter.WriteAndClose([]byte(msg))
err := buildJob.Finish(ctx, FinishStateErrored)
if err != nil {
logger := context.LoggerFromContext(ctx).WithField("self", "step_write_worker_info")
logger.WithField("err", err).Error("couldn't error the job")
}
return multistep.ActionHalt
}
}
return multistep.ActionContinue
}
func (s *stepWriteWorkerInfo) Cleanup(state multistep.StateBag) {}