Class: Jenkins::Job

Inherits:
Object
  • Object
show all
Defined in:
lib/jenkins-json-api/job.rb

Constant Summary collapse

SUCCESS =
'blue'
FAILED =
'red'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(json) ⇒ Job

Returns a new instance of Job.



9
10
11
12
13
# File 'lib/jenkins-json-api/job.rb', line 9

def initialize(json)
  @name = json['name']
  @url  = json['url']
  @color = json['color']
end

Instance Attribute Details

#colorObject (readonly)

Returns the value of attribute color.



42
43
44
# File 'lib/jenkins-json-api/job.rb', line 42

def color
  @color
end

#nameObject (readonly)

Returns the value of attribute name.



42
43
44
# File 'lib/jenkins-json-api/job.rb', line 42

def name
  @name
end

#urlObject (readonly)

Returns the value of attribute url.



42
43
44
# File 'lib/jenkins-json-api/job.rb', line 42

def url
  @url
end

Instance Method Details

#==(r) ⇒ Object



36
37
38
39
40
# File 'lib/jenkins-json-api/job.rb', line 36

def ==(r)
  r.name == name and
  r.url  == url  and
  r.success? == success?
end

#buildObject



21
22
23
# File 'lib/jenkins-json-api/job.rb', line 21

def build
  open url+'build'
end

#build_asyncObject



25
26
27
28
29
30
# File 'lib/jenkins-json-api/job.rb', line 25

def build_async
  Process.waitpid @job if @job
  @job = fork do
    build
  end
end

#success?Boolean

Returns:

  • (Boolean)


15
16
17
18
19
# File 'lib/jenkins-json-api/job.rb', line 15

def success?
  return true if color == SUCCESS
  return false if color == FAILED
  raise "Inconsistent class state! color: #{color}"
end

#to_sObject



32
33
34
# File 'lib/jenkins-json-api/job.rb', line 32

def to_s
  "\n  #{super.to_s}\n    name: #{name}\n    url: #{url}\n    success: #{success?}\n"
end