Class: Jbcm::Client::Job

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cli, job_name = nil) ⇒ Job

Returns a new instance of Job.



37
38
39
40
# File 'lib/jbcm.rb', line 37

def initialize(cli, job_name = nil)
  @cli = cli
  @job_name = job_name
end

Instance Attribute Details

#cliObject (readonly)

Returns the value of attribute cli.



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

def cli
  @cli
end

#job_nameObject (readonly)

Returns the value of attribute job_name.



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

def job_name
  @job_name
end

Instance Method Details

#build_commandObject



55
56
57
# File 'lib/jbcm.rb', line 55

def build_command
  config.elements['project/builders/hudson.tasks.Shell/command'].text
end

#build_command=(build_command) ⇒ Object



59
60
61
# File 'lib/jbcm.rb', line 59

def build_command=(build_command)
  config.elements['project/builders/hudson.tasks.Shell/command'].text = build_command
end

#configObject



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

def config
  @config ||= REXML::Document.new(cli.conn.get("job/#{job_name}/config.xml").body)
end

#list(raw: false) ⇒ Object



42
43
44
45
46
47
48
49
# File 'lib/jbcm.rb', line 42

def list(raw: false)
  response = cli.conn.get('api/json')
  if raw
    JSON.parse(response.body)
  else
    JSON.parse(response.body)['jobs']
  end
end

#updateObject



63
64
65
66
67
68
69
# File 'lib/jbcm.rb', line 63

def update
  cli.conn.post do |req|
    req.url "job/#{job_name}/config.xml"
    req.headers['Content-Type'] = 'application/xml'
    req.body = config.to_s
  end
end

#update!Object



71
72
73
74
75
76
77
78
# File 'lib/jbcm.rb', line 71

def update!
  request_result = update
  if request_result.status == 200
    $stdout.puts 'update successfully.'
  else
    fail "Update failed! return #{request_result.status}"
  end
end