forked from cvbarros/go-teamcity
/
step.go
82 lines (71 loc) · 2.42 KB
/
step.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
package teamcity
import (
"encoding/json"
"fmt"
)
// BuildStepType represents most common step types for build steps
type BuildStepType = string
const (
//StepTypePowershell step type
StepTypePowershell BuildStepType = "jetbrains_powershell"
//StepTypeDotnetCli step type
StepTypeDotnetCli BuildStepType = "dotnet.cli"
//StepTypeCommandLine (shell/cmd) step type
StepTypeCommandLine BuildStepType = "simpleRunner"
)
//StepExecuteMode represents how a build configuration step will execute regarding others.
type StepExecuteMode = string
const (
//StepExecuteModeDefault executes the step only if all previous steps finished successfully.
StepExecuteModeDefault = "default"
//StepExecuteModeOnlyIfBuildIsSuccessful executes the step only if the whole build is successful.
StepExecuteModeOnlyIfBuildIsSuccessful = "execute_if_success"
//StepExecuteModeEvenWhenFailed executes the step even if previous steps failed.
StepExecuteModeEvenWhenFailed = "execute_if_failed"
//StepExecuteAlways executes even if build stop command was issued.
StepExecuteAlways = "execute_always"
)
// Step interface represents a a build configuration/template build step. To interact with concrete step types, see the Step* types.
type Step interface {
GetID() string
GetName() string
Type() string
}
type stepJSON struct {
Disabled *bool `json:"disabled,omitempty" xml:"disabled"`
Href string `json:"href,omitempty" xml:"href"`
ID string `json:"id,omitempty" xml:"id"`
Inherited *bool `json:"inherited,omitempty" xml:"inherited"`
Name string `json:"name,omitempty" xml:"name"`
Properties *Properties `json:"properties,omitempty"`
Type string `json:"type,omitempty" xml:"type"`
}
type stepsJSON struct {
Count int32 `json:"count,omitempty" xml:"count"`
Items []*stepJSON `json:"step"`
}
var stepReadingFunc = func(dt []byte, out interface{}) error {
var payload stepJSON
if err := json.Unmarshal(dt, &payload); err != nil {
return err
}
var step Step
switch payload.Type {
case string(StepTypePowershell):
var ps StepPowershell
if err := ps.UnmarshalJSON(dt); err != nil {
return err
}
step = &ps
case string(StepTypeCommandLine):
var cmd StepCommandLine
if err := cmd.UnmarshalJSON(dt); err != nil {
return err
}
step = &cmd
default:
return fmt.Errorf("Unsupported step type: '%s' (id:'%s')", payload.Type, payload.ID)
}
replaceValue(out, &step)
return nil
}