Class: Buildkite::Pipelines::Command
- Inherits:
-
Object
- Object
- Buildkite::Pipelines::Command
show all
- Defined in:
- lib/buildkite/pipelines/command.rb
Defined Under Namespace
Classes: CommandFailedError, Result
Constant Summary
collapse
- BIN_PATH =
'buildkite-agent'
- COMMANDS =
%w(
pipeline
artifact
annotate
meta_data
)
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(command, subcommand, *args) ⇒ Command
Returns a new instance of Command.
71
72
73
74
75
76
|
# File 'lib/buildkite/pipelines/command.rb', line 71
def initialize(command, subcommand, *args)
@command = command.to_s
@subcommand = subcommand.to_s
@options = (args)
@args = transform_args(args)
end
|
Class Method Details
.annotate(body, *args, exception: false) ⇒ Object
49
50
51
|
# File 'lib/buildkite/pipelines/command.rb', line 49
def annotate(body, *args, exception: false)
new(:annotate, body, *args).run(exception: exception)
end
|
.artifact(subcommand, *args, exception: false) ⇒ Object
40
41
42
43
44
45
46
47
|
# File 'lib/buildkite/pipelines/command.rb', line 40
def artifact(subcommand, *args, exception: false)
result = new(:artifact, subcommand, *args).run(exception: exception)
case subcommand.to_s
when 'shasum', 'search' then result.output
else result
end
end
|
53
54
55
56
57
58
59
60
|
# File 'lib/buildkite/pipelines/command.rb', line 53
def meta_data(subcommand, *args, exception: false)
result = new(:'meta-data', subcommand, *args).run(exception: exception)
case subcommand.to_s
when 'get', 'keys' then result.output
else result
end
end
|
.pipeline(subcommand, *args, exception: false) ⇒ Object
36
37
38
|
# File 'lib/buildkite/pipelines/command.rb', line 36
def pipeline(subcommand, *args, exception: false)
new(:pipeline, subcommand, *args).run(exception: exception)
end
|
Instance Method Details
#run(exception: false) ⇒ Object
78
79
80
81
82
83
84
85
86
87
|
# File 'lib/buildkite/pipelines/command.rb', line 78
def run(exception: false)
stdout, stderr, status = Open3.capture3(*to_a)
result = Result.new(stdout, stderr, status)
if !result.success? && exception
raise CommandFailedError, "#{result.output}"
else
result
end
end
|