forked from concourse/concourse
/
job_config.go
130 lines (105 loc) · 2.74 KB
/
job_config.go
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
package atc
type JobConfig struct {
Name string `json:"name"`
OldName string `json:"old_name,omitempty"`
Public bool `json:"public,omitempty"`
DisableManualTrigger bool `json:"disable_manual_trigger,omitempty"`
Serial bool `json:"serial,omitempty"`
Interruptible bool `json:"interruptible,omitempty"`
SerialGroups []string `json:"serial_groups,omitempty"`
RawMaxInFlight int `json:"max_in_flight,omitempty"`
BuildLogsToRetain int `json:"build_logs_to_retain,omitempty"`
BuildLogRetention *BuildLogRetention `json:"build_log_retention,omitempty"`
OnSuccess *Step `json:"on_success,omitempty"`
OnFailure *Step `json:"on_failure,omitempty"`
OnAbort *Step `json:"on_abort,omitempty"`
OnError *Step `json:"on_error,omitempty"`
Ensure *Step `json:"ensure,omitempty"`
PlanSequence []Step `json:"plan"`
}
type BuildLogRetention struct {
Builds int `json:"builds,omitempty"`
MinimumSucceededBuilds int `json:"minimum_succeeded_builds,omitempty"`
Days int `json:"days,omitempty"`
}
func (config JobConfig) Step() Step {
return Step{Config: config.StepConfig()}
}
func (config JobConfig) StepConfig() StepConfig {
var step StepConfig = &DoStep{
Steps: config.PlanSequence,
}
if config.OnSuccess != nil {
step = &OnSuccessStep{
Step: step,
Hook: *config.OnSuccess,
}
}
if config.OnFailure != nil {
step = &OnFailureStep{
Step: step,
Hook: *config.OnFailure,
}
}
if config.OnAbort != nil {
step = &OnAbortStep{
Step: step,
Hook: *config.OnAbort,
}
}
if config.OnError != nil {
step = &OnErrorStep{
Step: step,
Hook: *config.OnError,
}
}
if config.Ensure != nil {
step = &EnsureStep{
Step: step,
Hook: *config.Ensure,
}
}
return step
}
func (config JobConfig) MaxInFlight() int {
if config.Serial || len(config.SerialGroups) > 0 {
return 1
}
if config.RawMaxInFlight != 0 {
return config.RawMaxInFlight
}
return 0
}
func (config JobConfig) Inputs() []JobInputParams {
var inputs []JobInputParams
_ = config.StepConfig().Visit(StepRecursor{
OnGet: func(step *GetStep) error {
inputs = append(inputs, JobInputParams{
JobInput: JobInput{
Name: step.Name,
Resource: step.ResourceName(),
Passed: step.Passed,
Version: step.Version,
Trigger: step.Trigger,
},
Params: step.Params,
Tags: step.Tags,
})
return nil
},
})
return inputs
}
func (config JobConfig) Outputs() []JobOutput {
var outputs []JobOutput
_ = config.StepConfig().Visit(StepRecursor{
OnPut: func(step *PutStep) error {
outputs = append(outputs, JobOutput{
Name: step.Name,
Resource: step.ResourceName(),
})
return nil
},
})
return outputs
}