Class: Janky::Build
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Janky::Build
- Defined in:
- lib/janky/build.rb
Class Attribute Summary collapse
-
.base_url ⇒ Object
The full URL of the web app as a String, including the protocol.
-
.url ⇒ Object
readonly
The full URL to the Jenkins build page, as a String.
Class Method Summary collapse
-
.complete(id, green) ⇒ Object
Transition the Build to the completed state.
-
.completed ⇒ Object
Find all completed builds, most recent first.
-
.green ⇒ Object
Find all green builds, most recent first.
-
.queued ⇒ Object
Find all builds that have been queued in Jenkins, most recent first.
-
.start(id, url) ⇒ Object
Transition the Build to the started state.
-
.started ⇒ Object
Find all started builds, most recent first.
Instance Method Summary collapse
- #branch_name ⇒ Object
-
#branch_url ⇒ Object
URL of the web page for this build’s branch, served by Janky::App.
-
#builder ⇒ Object
See Repository#builder.
-
#building? ⇒ Boolean
Is this build currently being built?.
- #commit_author ⇒ Object
- #commit_message ⇒ Object
- #commit_url ⇒ Object
-
#complete(green, now) ⇒ Object
Mark the build as complete, store the build output and notify Campfire.
-
#completed? ⇒ Boolean
Did this build complete?.
-
#duration ⇒ Object
The time it took to peform this build in seconds.
- #number ⇒ Object
-
#output ⇒ Object
Cached or remote build output.
-
#output_remote ⇒ Object
Retrieve the build output from the Jenkins server.
-
#pending? ⇒ Boolean
Is this build currently sitting in the queue waiting to be built?.
-
#queued? ⇒ Boolean
Has this build been queued in Jenkins?.
-
#red? ⇒ Boolean
Is this build red?.
- #repo ⇒ Object
- #repo_id ⇒ Object
- #repo_job_name ⇒ Object
- #repo_name ⇒ Object
- #repo_nwo ⇒ Object
- #repository ⇒ Object
-
#rerun(new_room_id = nil) ⇒ Object
Run a copy of itself.
-
#room_name ⇒ Object
The name of the Campfire room where notifications are sent.
-
#run ⇒ Object
Trigger a Jenkins build using the appropriate builder.
- #sha1 ⇒ Object
- #short_sha1 ⇒ Object
-
#start(url, now) ⇒ Object
Mark the build as started.
-
#started? ⇒ Boolean
Was this build ever started?.
-
#web_url ⇒ Object
URL of this build’s web page, served by Janky::App.
Class Attribute Details
.base_url ⇒ Object
The full URL of the web app as a String, including the protocol.
224 225 226 |
# File 'lib/janky/build.rb', line 224 def base_url @base_url end |
.url ⇒ Object (readonly)
The full URL to the Jenkins build page, as a String.
227 228 229 |
# File 'lib/janky/build.rb', line 227 def url @url end |
Class Method Details
.complete(id, green) ⇒ Object
Transition the Build to the completed state.
id - the Fixnum ID used to find the build. green - Boolean indicating build success.
Returns nothing or raises an Error for inexistant builds.
38 39 40 41 42 43 44 |
# File 'lib/janky/build.rb', line 38 def self.complete(id, green) if build = find_by_id(id) build.complete(green, Time.now) else raise Error, "Unknown build: #{id.inspect}" end end |
.completed ⇒ Object
Find all completed builds, most recent first.
Returns an Array of Builds.
63 64 65 66 |
# File 'lib/janky/build.rb', line 63 def self.completed started. where("completed_at IS NOT NULL") end |
.green ⇒ Object
Find all green builds, most recent first.
Returns an Array of Builds.
71 72 73 |
# File 'lib/janky/build.rb', line 71 def self.green completed.where(:green => true) end |
.queued ⇒ Object
Find all builds that have been queued in Jenkins, most recent first.
Returns an Array of Build objects.
49 50 51 |
# File 'lib/janky/build.rb', line 49 def self.queued where("queued_at IS NOT NULL").order("queued_at DESC, id DESC") end |
.start(id, url) ⇒ Object
Transition the Build to the started state.
id - the Fixnum ID used to find the build. url - the full String URL of the build.
Returns nothing or raises an Error for inexistant builds.
24 25 26 27 28 29 30 |
# File 'lib/janky/build.rb', line 24 def self.start(id, url) if build = find_by_id(id) build.start(url, Time.now) else raise Error, "Unknown build: #{id.inspect}" end end |
.started ⇒ Object
Find all started builds, most recent first.
Returns an Array of Builds.
56 57 58 |
# File 'lib/janky/build.rb', line 56 def self.started where("started_at IS NOT NULL").order("started_at DESC, id DESC") end |
Instance Method Details
#branch_name ⇒ Object
294 295 296 |
# File 'lib/janky/build.rb', line 294 def branch_name branch.name end |
#branch_url ⇒ Object
URL of the web page for this build’s branch, served by Janky::App.
Returns the URL as a String.
241 242 243 244 |
# File 'lib/janky/build.rb', line 241 def branch_url return if new_record? self.class.base_url + "#{repo_name}/#{branch_name}" end |
#builder ⇒ Object
See Repository#builder.
127 128 129 |
# File 'lib/janky/build.rb', line 127 def builder branch.repository.builder end |
#building? ⇒ Boolean
Is this build currently being built?
Returns a Boolean.
93 94 95 |
# File 'lib/janky/build.rb', line 93 def building? started? && !completed? end |
#commit_author ⇒ Object
286 287 288 |
# File 'lib/janky/build.rb', line 286 def commit. end |
#commit_message ⇒ Object
282 283 284 |
# File 'lib/janky/build.rb', line 282 def commit. end |
#commit_url ⇒ Object
278 279 280 |
# File 'lib/janky/build.rb', line 278 def commit_url commit.url end |
#complete(green, now) ⇒ Object
Mark the build as complete, store the build output and notify Campfire.
green - Boolean indicating build success. now - the Time at which the build completed.
Returns nothing or raise an Error for weird transitions.
189 190 191 192 193 194 195 196 197 198 199 200 201 202 |
# File 'lib/janky/build.rb', line 189 def complete(green, now) if ! started? raise Error, "Build #{id} not started" elsif completed? raise Error, "Build #{id} already completed" else update_attributes!( :green => green, :completed_at => now, :output => output_remote ) Notifier.completed(self) end end |
#completed? ⇒ Boolean
Did this build complete?
Returns a Boolean.
114 115 116 |
# File 'lib/janky/build.rb', line 114 def completed? ! completed_at.nil? end |
#duration ⇒ Object
The time it took to peform this build in seconds.
Returns an Integer seconds.
207 208 209 210 211 |
# File 'lib/janky/build.rb', line 207 def duration if completed? Integer(completed_at - started_at) end end |
#number ⇒ Object
290 291 292 |
# File 'lib/janky/build.rb', line 290 def number id.to_s end |
#output ⇒ Object
Cached or remote build output.
Returns the String output.
147 148 149 150 151 152 153 154 155 |
# File 'lib/janky/build.rb', line 147 def output if completed? read_attribute(:output) elsif started? output_remote else "" end end |
#output_remote ⇒ Object
Retrieve the build output from the Jenkins server.
Returns the String output.
160 161 162 163 164 |
# File 'lib/janky/build.rb', line 160 def output_remote if started? builder.output(self) end end |
#pending? ⇒ Boolean
Is this build currently sitting in the queue waiting to be built?
Returns true if the build is queued and not started, false otherwise.
86 87 88 |
# File 'lib/janky/build.rb', line 86 def pending? queued? && !started? end |
#queued? ⇒ Boolean
Has this build been queued in Jenkins?
Returns true when the build is complete or currently being built,
false otherwise.
79 80 81 |
# File 'lib/janky/build.rb', line 79 def queued? ! queued_at.nil? end |
#red? ⇒ Boolean
Is this build red?
Returns a Boolean, nothing when the build hasn’t completed yet.
100 101 102 |
# File 'lib/janky/build.rb', line 100 def red? completed? && !green? end |
#repo ⇒ Object
266 267 268 |
# File 'lib/janky/build.rb', line 266 def repo branch.repository end |
#repo_id ⇒ Object
246 247 248 |
# File 'lib/janky/build.rb', line 246 def repo_id repository.id end |
#repo_job_name ⇒ Object
250 251 252 |
# File 'lib/janky/build.rb', line 250 def repo_job_name repository.job_name end |
#repo_name ⇒ Object
254 255 256 |
# File 'lib/janky/build.rb', line 254 def repo_name repository.name end |
#repo_nwo ⇒ Object
258 259 260 |
# File 'lib/janky/build.rb', line 258 def repo_nwo repository.nwo end |
#repository ⇒ Object
262 263 264 |
# File 'lib/janky/build.rb', line 262 def repository branch.repository end |
#rerun(new_room_id = nil) ⇒ Object
Run a copy of itself. Typically used to force a build in case of temporary test failure or when auto-build is disabled.
new_room_id - optional Campfire room String ID. Defaults to the room of the
build being re-run.
Returns the build copy.
138 139 140 141 142 |
# File 'lib/janky/build.rb', line 138 def rerun(new_room_id = nil) build = branch.build_for(commit, new_room_id) build.run build end |
#room_name ⇒ Object
The name of the Campfire room where notifications are sent.
Returns the String room name.
216 217 218 219 220 |
# File 'lib/janky/build.rb', line 216 def room_name if room_id && !room_id.empty? ChatService.room_name(room_id) end end |
#run ⇒ Object
Trigger a Jenkins build using the appropriate builder.
Returns nothing.
121 122 123 124 |
# File 'lib/janky/build.rb', line 121 def run builder.run(self) update_attributes!(:queued_at => Time.now) end |
#sha1 ⇒ Object
270 271 272 |
# File 'lib/janky/build.rb', line 270 def sha1 commit.sha1 end |
#short_sha1 ⇒ Object
274 275 276 |
# File 'lib/janky/build.rb', line 274 def short_sha1 sha1[0,7] end |
#start(url, now) ⇒ Object
Mark the build as started.
url - the full String URL of the build on the Jenkins server. now - the Time at which the build started.
Returns nothing or raise an Error for weird transitions.
172 173 174 175 176 177 178 179 180 181 |
# File 'lib/janky/build.rb', line 172 def start(url, now) if started? raise Error, "Build #{id} already started" elsif completed? raise Error, "Build #{id} already completed" else update_attributes!(:url => url, :started_at => now) Notifier.started(self) end end |
#started? ⇒ Boolean
Was this build ever started?
Returns a Boolean.
107 108 109 |
# File 'lib/janky/build.rb', line 107 def started? ! started_at.nil? end |
#web_url ⇒ Object
URL of this build’s web page, served by Janky::App.
Returns the URL as a String.
233 234 235 236 |
# File 'lib/janky/build.rb', line 233 def web_url return if new_record? self.class.base_url + "#{id}/output" end |