Class: Hudkins::Job
- Inherits:
-
Object
- Object
- Hudkins::Job
- Extended by:
- Mixin
- Includes:
- Comparable, Common
- Defined in:
- lib/hudkins/job.rb
Overview
Description
Primary class for interacting with a Hudson job
Examples
hud = Hudkins.new "http://hudson.com"
job = hud.jobs.find_by_name :job_name
job.disabled? # => true
job.disabled = false
job.post_config!
attr_accessor_from_config methods
I created custom attr_accessor like DSL methods that create accessor like methods for the Hudkins::Job object to easily interact with the xml config. Paradigm is to use method_name? for boolean values and method_name! for any methods that post updates to the server.
Instance Attribute Summary collapse
-
#color ⇒ Object
readonly
Returns the value of attribute color.
-
#config ⇒ Object
readonly
Description accessor for job’s config.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
-
#<=>(other) ⇒ Object
Enumerables/Comparables…
-
#blocked_by_upstream ⇒ Object
:attr_accessor: blocked_by_upstream.
- #build! ⇒ Object
-
#can_roam ⇒ Object
:attr_accessor: can_roam.
-
#concurrent_builds ⇒ Object
:attr_accessor: concurrent_builds.
-
#copy(new_job_name) ⇒ Object
Description Copy job to new_job_name.
- #delete! ⇒ Object
-
#description ⇒ Object
:attr_accessor: description.
- #disable! ⇒ Object
-
#disabled ⇒ Object
:attr_accessor: disabled.
- #enable! ⇒ Object
-
#initialize(hudkins, data) ⇒ Job
constructor
A new instance of Job.
- #inspect ⇒ Object
-
#post_config! ⇒ Object
Description Post the job’s config back to the server to update it.
-
#quick_description!(msg = nil) ⇒ Object
Description The remote api allows for updating just the description.
- #recreate! ⇒ Object
-
#rotate_logs_days ⇒ Object
:attr_accessor: :rotate_logs_days Number of days to keep builds -1 == infinite.
-
#rotate_logs_num ⇒ Object
:attr_accessor: :rotate_logs_num Number of builds to keep -1 == infinite.
-
#scm_url ⇒ Object
:attr_accessor: scm_url.
-
#update_config(config = nil) ⇒ Object
Description get the job’s config takes string (xml) or other’s config.
Methods included from Mixin
attr_accessor_from_config, attr_post_from_config, attr_reader_from_config, attr_writer_from_config
Methods included from Common
#check_host_availability, #get, #host_available?, #hudkins, #post, #url_escape
Constructor Details
#initialize(hudkins, data) ⇒ Job
Returns a new instance of Job.
61 62 63 64 65 66 67 |
# File 'lib/hudkins/job.rb', line 61 def initialize hudkins, data @hudkins = hudkins @name = data["name"] @url = URI.parse data["url"] @color = data["color"] @path = @url.path end |
Instance Attribute Details
#color ⇒ Object (readonly)
Returns the value of attribute color.
25 26 27 |
# File 'lib/hudkins/job.rb', line 25 def color @color end |
#config ⇒ Object (readonly)
Description
accessor for job’s config. Initializes then caches. Use update_config if out of date.
102 103 104 |
# File 'lib/hudkins/job.rb', line 102 def config @config end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
25 26 27 |
# File 'lib/hudkins/job.rb', line 25 def name @name end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
25 26 27 |
# File 'lib/hudkins/job.rb', line 25 def path @path end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
25 26 27 |
# File 'lib/hudkins/job.rb', line 25 def url @url end |
Instance Method Details
#<=>(other) ⇒ Object
Enumerables/Comparables…
78 79 80 81 |
# File 'lib/hudkins/job.rb', line 78 def <=> other # TODO how do I implement jobs.sort(&:path) ? self.name <=> other.name end |
#blocked_by_upstream ⇒ Object
:attr_accessor: blocked_by_upstream
43 |
# File 'lib/hudkins/job.rb', line 43 attr_accessor_from_config :blocked_by_upstream, "//project//blockBuildWhenUpstreamBuilding", :bool |
#build! ⇒ Object
113 114 115 |
# File 'lib/hudkins/job.rb', line 113 def build! get path + "/build" end |
#can_roam ⇒ Object
:attr_accessor: can_roam
37 |
# File 'lib/hudkins/job.rb', line 37 attr_accessor_from_config :can_roam, "//project//canRoam", :bool |
#concurrent_builds ⇒ Object
:attr_accessor: concurrent_builds
46 |
# File 'lib/hudkins/job.rb', line 46 attr_accessor_from_config :concurrent_builds, "//project//concurrentBuild", :bool |
#copy(new_job_name) ⇒ Object
Description
Copy job to new_job_name
Example
new_job = job.copy "new-job-name"
new_job.scm_url = "http://svn/new/job/path"
new_job.post_config!
158 159 160 161 162 163 164 |
# File 'lib/hudkins/job.rb', line 158 def copy new_job_name # post /createItem?name=NEWJOBNAME&mode=copy&from=FROMJOBNAME response = post "/createItem?" + url_escape(:name => new_job_name, :mode => "copy", :from => name) # return new job object hudkins.update_jobs.find_by_name new_job_name if response.success? end |
#delete! ⇒ Object
117 118 119 |
# File 'lib/hudkins/job.rb', line 117 def delete! post path + "/doDelete" end |
#description ⇒ Object
:attr_accessor: description
34 |
# File 'lib/hudkins/job.rb', line 34 attr_accessor_from_config :description, "//project//descriptoin" |
#disable! ⇒ Object
125 126 127 |
# File 'lib/hudkins/job.rb', line 125 def disable! post path + "/disable" end |
#disabled ⇒ Object
:attr_accessor: disabled
40 |
# File 'lib/hudkins/job.rb', line 40 attr_accessor_from_config :disabled, "//project//disabled", :bool |
#enable! ⇒ Object
129 130 131 |
# File 'lib/hudkins/job.rb', line 129 def enable! post path + "/enable" end |
#inspect ⇒ Object
69 70 71 |
# File 'lib/hudkins/job.rb', line 69 def inspect super "@name=#{@name}" end |
#post_config! ⇒ Object
Description
Post the job’s config back to the server to update it.
109 110 111 |
# File 'lib/hudkins/job.rb', line 109 def post_config! post path + "/config.xml", @config end |
#quick_description!(msg = nil) ⇒ Object
Description
The remote api allows for updating just the description. I had to tweak the name because I still wanted description to be an attr_accessor_from_config
Example
job.quick_description! # => "this is the description for job"
job.quick_description! = "this is the new desc." # => Response obj
141 142 143 144 145 146 147 148 |
# File 'lib/hudkins/job.rb', line 141 def quick_description! msg = nil # another yuck! if msg post path + "/description?" + url_escape(:description => msg) else get( path + "/description" ).body end end |
#recreate! ⇒ Object
121 122 123 |
# File 'lib/hudkins/job.rb', line 121 def recreate! hudkins.add_job name, config end |
#rotate_logs_days ⇒ Object
:attr_accessor: :rotate_logs_days Number of days to keep builds -1 == infinite
59 |
# File 'lib/hudkins/job.rb', line 59 attr_accessor_from_config :rotate_logs_days, "//logRotator/daysToKeep", Integer |
#rotate_logs_num ⇒ Object
:attr_accessor: :rotate_logs_num Number of builds to keep -1 == infinite
54 |
# File 'lib/hudkins/job.rb', line 54 attr_accessor_from_config :rotate_logs_num, "//logRotator/numToKeep", :int |
#scm_url ⇒ Object
:attr_accessor: scm_url
31 |
# File 'lib/hudkins/job.rb', line 31 attr_accessor_from_config :scm_url, "//scm//remote" |
#update_config(config = nil) ⇒ Object
Description
get the job’s config takes string (xml) or other’s config
87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/hudkins/job.rb', line 87 def update_config config = nil config = case config when String then hudkins.parse_string( config, :xml ) when Nokogiri::XML::Document, NilClass then config else raise "unknown config type #{config.class}" end @config = config || hudkins.get_parsed( path + "/config.xml", :accept => "application/xml" ) end |