Class: Buildkite::Pipeline

Inherits:
Object
  • Object
show all
Defined in:
lib/buildkite.rb

Overview

Here is a comment.

Instance Method Summary collapse

Constructor Details

#initializePipeline

Returns a new instance of Pipeline.



11
12
13
14
15
16
17
# File 'lib/buildkite.rb', line 11

def initialize
  @steps = []
  @agents = nil
  @env = nil
  @notify = nil
  @secrets = nil
end

Instance Method Details

#add_agent(key, value) ⇒ Object



23
24
25
26
# File 'lib/buildkite.rb', line 23

def add_agent(key, value)
  @agents = {} if @agents.nil?
  @agents[key] = value
end

#add_environment_variable(key, value) ⇒ Object



28
29
30
31
# File 'lib/buildkite.rb', line 28

def add_environment_variable(key, value)
  @env = {} if @env.nil?
  @env[key] = value
end

#add_notify(notify) ⇒ Object



33
34
35
# File 'lib/buildkite.rb', line 33

def add_notify(notify)
  @notify = notify
end

#add_step(step) ⇒ self

Adds a step to the pipeline.

Examples:

Adding a CommandStep

command_step = Buildkite::CommandStep.new(label: "Run tests", commands: ["bundle exec rspec"])
pipeline.add_step(command_step)

Adding a BlockStep

block_step = Buildkite::BlockStep.new(label: "Manual approval", block: "Deploy to production")
pipeline.add_step(block_step)

Parameters:

  • step (Buildkite::CommandStep, Buildkite::BlockStep)

    The step to add, which can be either a CommandStep or a BlockStep.

Returns:

  • (self)

    Returns the pipeline itself for chaining.



51
52
53
54
# File 'lib/buildkite.rb', line 51

def add_step(step)
  @steps << step
  self
end

#buildObject



56
57
58
59
60
61
62
63
64
65
# File 'lib/buildkite.rb', line 56

def build
  pipeline = {
    "steps" => @steps
  }
  pipeline["agents"] = @agents unless @agents.nil?
  pipeline["env"] = @env unless @env.nil?
  pipeline["notify"] = @notify unless @notify.nil?
  pipeline["secrets"] = @secrets unless @secrets.nil?
  pipeline
end

#set_secrets(secrets) ⇒ Object



19
20
21
# File 'lib/buildkite.rb', line 19

def set_secrets(secrets)
  @secrets = secrets
end

#to_json(*_args) ⇒ Object



67
68
69
# File 'lib/buildkite.rb', line 67

def to_json(*_args)
  JSON.pretty_generate(build, indent: "    ")
end

#to_yamlObject



71
72
73
# File 'lib/buildkite.rb', line 71

def to_yaml
  build.to_yaml
end