Class: Hudson::Job
- Inherits:
-
Object
- Object
- Hudson::Job
- Defined in:
- lib/hudson-remote-api/job.rb
Overview
This class provides an interface to Hudson jobs
Instance Attribute Summary collapse
-
#config ⇒ Object
Returns the value of attribute config.
-
#description ⇒ Object
Returns the value of attribute description.
-
#name ⇒ Object
Returns the value of attribute name.
-
#parameterized_job ⇒ Object
Returns the value of attribute parameterized_job.
-
#repository_browser_location ⇒ Object
Returns the value of attribute repository_browser_location.
-
#repository_url ⇒ Object
Returns the value of attribute repository_url.
-
#repository_urls ⇒ Object
Returns the value of attribute repository_urls.
Class Method Summary collapse
- .create(name, config = nil) ⇒ Object
- .get(job_name) ⇒ Object
-
.list ⇒ Object
List all Hudson jobs.
-
.list_active ⇒ Object
List all jobs in active execution.
Instance Method Summary collapse
- #active? ⇒ Boolean
-
#build(params = {}) ⇒ Object
Start building this job on Hudson server.
- #builds_list ⇒ Object
- #color ⇒ Object
-
#copy(new_job = nil) ⇒ Object
Create a new job on Hudson server based on the current job object.
-
#delete ⇒ Object
Delete this job from Hudson server.
- #disable ⇒ Object
- #enable ⇒ Object
- #free_style_project? ⇒ Boolean
-
#initialize(name, config = nil) ⇒ Job
constructor
Instance methods.
- #last_build ⇒ Object
- #last_completed_build ⇒ Object
- #last_failed_build ⇒ Object
- #last_stable_build ⇒ Object
- #last_successful_build ⇒ Object
- #last_unsuccessful_build ⇒ Object
-
#load_config ⇒ Object
(also: #reload_config)
Load data from Hudson’s Job configuration settings into class variables.
- #next_build_number ⇒ Object
- #triggers ⇒ Object
- #triggers=(opts = {}) ⇒ Object
- #wait_for_build_to_finish(poll_freq = 10) ⇒ Object
- #wipe_out_workspace ⇒ Object
Constructor Details
#initialize(name, config = nil) ⇒ Job
Instance methods
39 40 41 42 43 44 45 |
# File 'lib/hudson-remote-api/job.rb', line 39 def initialize(name, config=nil) name.strip! # Creates the job in Hudson if it doesn't already exist @name = Job.list.include?(name) ? name : Job.create(name, config).name load_config self end |
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
4 5 6 |
# File 'lib/hudson-remote-api/job.rb', line 4 def config @config end |
#description ⇒ Object
Returns the value of attribute description.
4 5 6 |
# File 'lib/hudson-remote-api/job.rb', line 4 def description @description end |
#name ⇒ Object
Returns the value of attribute name.
4 5 6 |
# File 'lib/hudson-remote-api/job.rb', line 4 def name @name end |
#parameterized_job ⇒ Object
Returns the value of attribute parameterized_job.
4 5 6 |
# File 'lib/hudson-remote-api/job.rb', line 4 def parameterized_job @parameterized_job end |
#repository_browser_location ⇒ Object
Returns the value of attribute repository_browser_location.
4 5 6 |
# File 'lib/hudson-remote-api/job.rb', line 4 def repository_browser_location @repository_browser_location end |
#repository_url ⇒ Object
Returns the value of attribute repository_url.
4 5 6 |
# File 'lib/hudson-remote-api/job.rb', line 4 def repository_url @repository_url end |
#repository_urls ⇒ Object
Returns the value of attribute repository_urls.
4 5 6 |
# File 'lib/hudson-remote-api/job.rb', line 4 def repository_urls @repository_urls end |
Class Method Details
.create(name, config = nil) ⇒ Object
29 30 31 32 33 34 |
# File 'lib/hudson-remote-api/job.rb', line 29 def create(name, config=nil) config ||= File.open(File.dirname(__FILE__) + '/new_job_config.xml').read response = Hudson.client.create_item!({:name=>name, :mode=>"hudson.model.FreeStyleProject", :config=>config}) raise(APIError, "Error creating job #{name}: #{response.body}") if response.class != Net::HTTPFound Job.get(name) end |
.get(job_name) ⇒ Object
24 25 26 27 |
# File 'lib/hudson-remote-api/job.rb', line 24 def get(job_name) job_name.strip! list.include?(job_name) ? Job.new(job_name) : nil end |
Instance Method Details
#active? ⇒ Boolean
105 106 107 |
# File 'lib/hudson-remote-api/job.rb', line 105 def active? Job.list_active.include?(self.name) end |
#build(params = {}) ⇒ Object
Start building this job on Hudson server
171 172 173 174 175 176 177 178 |
# File 'lib/hudson-remote-api/job.rb', line 171 def build(params={}) if @parameterized_job response = Hudson.client.build_job_with_parameters!(self.name, params) else response = Hudson.client.build_job!(self.name) end response.is_a?(Net::HTTPSuccess) or response.is_a?(Net::HTTPRedirection) end |
#builds_list ⇒ Object
101 102 103 |
# File 'lib/hudson-remote-api/job.rb', line 101 def builds_list @job_info_parser.builds end |
#color ⇒ Object
69 70 71 |
# File 'lib/hudson-remote-api/job.rb', line 69 def color @color ||= @job_info_parser.color end |
#copy(new_job = nil) ⇒ Object
Create a new job on Hudson server based on the current job object
118 119 120 121 122 123 |
# File 'lib/hudson-remote-api/job.rb', line 118 def copy(new_job=nil) new_job = "copy_of_#{@name}" if new_job.nil? response = Hudson.client.create_item!({:name=>new_job, :mode=>"copy", :from=>@name}) raise(APIError, "Error copying job #{@name}: #{response.body}") if response.class != Net::HTTPFound Job.new(new_job) end |
#delete ⇒ Object
Delete this job from Hudson server
191 192 193 194 |
# File 'lib/hudson-remote-api/job.rb', line 191 def delete() response = Hudson.client.delete_job!(self.name) response.is_a?(Net::HTTPSuccess) or response.is_a?(Net::HTTPRedirection) end |
#disable ⇒ Object
180 181 182 183 |
# File 'lib/hudson-remote-api/job.rb', line 180 def disable() response = Hudson.client.disable_job!(self.name) response.is_a?(Net::HTTPSuccess) or response.is_a?(Net::HTTPRedirection) end |
#enable ⇒ Object
185 186 187 188 |
# File 'lib/hudson-remote-api/job.rb', line 185 def enable() response = Hudson.client.enable_job!(self.name) response.is_a?(Net::HTTPSuccess) or response.is_a?(Net::HTTPRedirection) end |
#free_style_project? ⇒ Boolean
65 66 67 |
# File 'lib/hudson-remote-api/job.rb', line 65 def free_style_project? @free_style_project ||= @job_info_parser.free_style_project? end |
#last_build ⇒ Object
73 74 75 |
# File 'lib/hudson-remote-api/job.rb', line 73 def last_build @job_info_parser.last_build end |
#last_completed_build ⇒ Object
77 78 79 |
# File 'lib/hudson-remote-api/job.rb', line 77 def last_completed_build @job_info_parser.last_completed_build end |
#last_failed_build ⇒ Object
81 82 83 |
# File 'lib/hudson-remote-api/job.rb', line 81 def last_failed_build @job_info_parser.last_failed_build end |
#last_stable_build ⇒ Object
85 86 87 |
# File 'lib/hudson-remote-api/job.rb', line 85 def last_stable_build @job_info_parser.last_stable_build end |
#last_successful_build ⇒ Object
89 90 91 |
# File 'lib/hudson-remote-api/job.rb', line 89 def last_successful_build @job_info_parser.last_successful_build end |
#last_unsuccessful_build ⇒ Object
93 94 95 |
# File 'lib/hudson-remote-api/job.rb', line 93 def last_unsuccessful_build @job_info_parser.last_unsuccessful_build end |
#load_config ⇒ Object Also known as: reload_config
Load data from Hudson’s Job configuration settings into class variables
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/hudson-remote-api/job.rb', line 48 def load_config @config = Hudson.client.job_config_info(self.name) @config_info_parser = Hudson::Parser::JobConfigInfo.new(@config) @config_writer = Hudson::XmlWriter::JobConfigInfo.new(self.name, @config) @info = Hudson.client.job_info(self.name) @job_info_parser = Hudson::Parser::JobInfo.new(@info) @description = @config_info_parser.description @parameterized_job = @config_info_parser.parameterized? @git = @config_info_parser.git_repo? @repository_url = @git ? @config_info_parser.git_repository : @config_info_parser.svn_repository @repostory_urls = @config_info_parser.svn_repository_urls @repository_browser_location = @config_info_parser.scm_broswer_location end |
#next_build_number ⇒ Object
97 98 99 |
# File 'lib/hudson-remote-api/job.rb', line 97 def next_build_number @job_info_parser.next_build_number end |
#triggers ⇒ Object
162 163 164 |
# File 'lib/hudson-remote-api/job.rb', line 162 def triggers @config_info_parser.triggers end |
#triggers=(opts = {}) ⇒ Object
157 158 159 160 |
# File 'lib/hudson-remote-api/job.rb', line 157 def triggers= opts={} @config_writer.triggers = opts reload_config end |
#wait_for_build_to_finish(poll_freq = 10) ⇒ Object
109 110 111 112 113 114 115 |
# File 'lib/hudson-remote-api/job.rb', line 109 def wait_for_build_to_finish(poll_freq=10) loop do puts "waiting for all #{@name} builds to finish" sleep poll_freq # wait break if !active? and !BuildQueue.list.include?(@name) end end |
#wipe_out_workspace ⇒ Object
196 197 198 199 200 201 202 203 204 205 |
# File 'lib/hudson-remote-api/job.rb', line 196 def wipe_out_workspace() wait_for_build_to_finish if !active? response = Hudson.client.wipeout_job_workspace!(self.name) else response = false end response.is_a?(Net::HTTPSuccess) or response.is_a?(Net::HTTPRedirection) end |