Module: Janky::Builder

Defined in:
lib/janky/builder.rb,
lib/janky/builder/http.rb,
lib/janky/builder/mock.rb,
lib/janky/builder/client.rb,
lib/janky/builder/runner.rb,
lib/janky/builder/payload.rb,
lib/janky/builder/receiver.rb

Overview

Triggers Jenkins builds and handles callbacks.

The HTTP requests flow goes like this:

  1. Send a Build request to the Jenkins server over HTTP. The resulting build URL is stored in Build#url.

  2. Once Jenkins picks up the build and starts running it, it sends a callback handled by the ‘receiver` Rack app, which transitions the build into a building state.

  3. Finally, Jenkins sends another callback with the build result and the build is transitioned to a completed and green/red state.

The Mock adapter provides methods to simulate that flow without having to go over the wire.

Defined Under Namespace

Classes: Client, HTTP, Mock, Payload, Receiver, Runner

Class Method Summary collapse

Class Method Details

.[](builder) ⇒ Object

Get the Client for a registered build host.

builder - the String name of the build host.

Returns the Client instance.



67
68
69
70
# File 'lib/janky/builder.rb', line 67

def self.[](builder)
  builders[builder] ||
    raise(Error, "Unknown builder: #{builder.inspect}")
end

.[]=(builder, url) ⇒ Object

Register a new build host.

url - The String URL of the Jenkins server.

Returns the new Client instance.



58
59
60
# File 'lib/janky/builder.rb', line 58

def self.[]=(builder, url)
  builders[builder] = Client.new(url, @callback_url)
end

.buildersObject

Registered build hosts.

Returns an Array of Client.



75
76
77
# File 'lib/janky/builder.rb', line 75

def self.builders
  @builders ||= {}
end

.choose(&block) ⇒ Object

Public: Define the rule for picking a builder.

block - Required block that will be given a Repository object when

picking a builder. Must return a Client object.

Returns nothing.



35
36
37
# File 'lib/janky/builder.rb', line 35

def self.choose(&block)
  @chooser = block
end

.complete!Object



104
105
106
# File 'lib/janky/builder.rb', line 104

def self.complete!
  builders.values.each { |b| b.complete! }
end

.enable_mock!Object



84
85
86
# File 'lib/janky/builder.rb', line 84

def self.enable_mock!
  builders.values.each { |b| b.enable_mock! }
end

.green!Object



88
89
90
# File 'lib/janky/builder.rb', line 88

def self.green!
  builders.values.each { |b| b.green! }
end

.pick_for(repo) ⇒ Object

Pick the appropriate builder for a repo based on the rule set by the choose method. Uses the default builder when no rule is defined.

repo - a Repository object.

Returns a Client object.



45
46
47
48
49
50
51
# File 'lib/janky/builder.rb', line 45

def self.pick_for(repo)
  if block = @chooser
    block.call(repo)
  else
    self[:default]
  end
end

.receiverObject

Rack app handling HTTP callbacks coming from the Jenkins server.



80
81
82
# File 'lib/janky/builder.rb', line 80

def self.receiver
  @receiver ||= Janky::Builder::Receiver
end

.red!Object



92
93
94
# File 'lib/janky/builder.rb', line 92

def self.red!
  builders.values.each { |b| b.red! }
end

.reset!Object



96
97
98
# File 'lib/janky/builder.rb', line 96

def self.reset!
  builders.values.each { |b| b.reset! }
end

.setup(callback_url) ⇒ Object

Set the callback URL of builder clients. Must be called before registering any client.

callback_url - The absolute callback URL as a String.

Returns nothing.



25
26
27
# File 'lib/janky/builder.rb', line 25

def self.setup(callback_url)
  @callback_url = callback_url
end

.start!Object



100
101
102
# File 'lib/janky/builder.rb', line 100

def self.start!
  builders.values.each { |b| b.start! }
end