jenkins-maestrodev 0.6.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (106) hide show
  1. checksums.yaml +7 -0
  2. data/Changelog.md +58 -0
  3. data/Gemfile +3 -0
  4. data/README.md +162 -0
  5. data/Rakefile +110 -0
  6. data/bin/jenkins +9 -0
  7. data/cucumber.yml +8 -0
  8. data/features/build_details.feature +44 -0
  9. data/features/configure.feature +36 -0
  10. data/features/default_host.feature +26 -0
  11. data/features/development.feature +14 -0
  12. data/features/listing_jobs.feature +34 -0
  13. data/features/manage_jobs.feature +263 -0
  14. data/features/manage_slave_nodes.feature +83 -0
  15. data/features/step_definitions/common_steps.rb +192 -0
  16. data/features/step_definitions/fixture_project_steps.rb +8 -0
  17. data/features/step_definitions/jenkins_steps.rb +116 -0
  18. data/features/step_definitions/scm_steps.rb +12 -0
  19. data/features/support/common.rb +37 -0
  20. data/features/support/env.rb +19 -0
  21. data/features/support/hooks.rb +16 -0
  22. data/features/support/jenkins_helpers.rb +6 -0
  23. data/features/support/matchers.rb +10 -0
  24. data/fixtures/jenkins/envfile.hpi +0 -0
  25. data/fixtures/jenkins/git.hpi +0 -0
  26. data/fixtures/jenkins/github.hpi +0 -0
  27. data/fixtures/jenkins/greenballs.hpi +0 -0
  28. data/fixtures/jenkins/rake.hpi +0 -0
  29. data/fixtures/jenkins/ruby.hpi +0 -0
  30. data/fixtures/projects/erlang/rebar.config +1 -0
  31. data/fixtures/projects/non-bundler/Rakefile +4 -0
  32. data/fixtures/projects/rails-3/.gitignore +4 -0
  33. data/fixtures/projects/rails-3/Gemfile +30 -0
  34. data/fixtures/projects/rails-3/Gemfile.lock +74 -0
  35. data/fixtures/projects/rails-3/README +256 -0
  36. data/fixtures/projects/rails-3/Rakefile +7 -0
  37. data/fixtures/projects/rails-3/app/controllers/application_controller.rb +3 -0
  38. data/fixtures/projects/rails-3/app/helpers/application_helper.rb +2 -0
  39. data/fixtures/projects/rails-3/app/views/layouts/application.html.erb +14 -0
  40. data/fixtures/projects/rails-3/config.ru +4 -0
  41. data/fixtures/projects/rails-3/config/application.rb +42 -0
  42. data/fixtures/projects/rails-3/config/boot.rb +13 -0
  43. data/fixtures/projects/rails-3/config/database.yml +22 -0
  44. data/fixtures/projects/rails-3/config/environment.rb +5 -0
  45. data/fixtures/projects/rails-3/config/environments/development.rb +26 -0
  46. data/fixtures/projects/rails-3/config/environments/production.rb +49 -0
  47. data/fixtures/projects/rails-3/config/environments/test.rb +35 -0
  48. data/fixtures/projects/rails-3/config/initializers/backtrace_silencers.rb +7 -0
  49. data/fixtures/projects/rails-3/config/initializers/inflections.rb +10 -0
  50. data/fixtures/projects/rails-3/config/initializers/mime_types.rb +5 -0
  51. data/fixtures/projects/rails-3/config/initializers/secret_token.rb +7 -0
  52. data/fixtures/projects/rails-3/config/initializers/session_store.rb +8 -0
  53. data/fixtures/projects/rails-3/config/locales/en.yml +5 -0
  54. data/fixtures/projects/rails-3/config/routes.rb +58 -0
  55. data/fixtures/projects/rails-3/db/seeds.rb +7 -0
  56. data/fixtures/projects/rails-3/doc/README_FOR_APP +2 -0
  57. data/fixtures/projects/rails-3/lib/tasks/.gitkeep +0 -0
  58. data/fixtures/projects/rails-3/public/404.html +26 -0
  59. data/fixtures/projects/rails-3/public/422.html +26 -0
  60. data/fixtures/projects/rails-3/public/500.html +26 -0
  61. data/fixtures/projects/rails-3/public/favicon.ico +0 -0
  62. data/fixtures/projects/rails-3/public/images/rails.png +0 -0
  63. data/fixtures/projects/rails-3/public/index.html +239 -0
  64. data/fixtures/projects/rails-3/public/javascripts/application.js +2 -0
  65. data/fixtures/projects/rails-3/public/javascripts/controls.js +965 -0
  66. data/fixtures/projects/rails-3/public/javascripts/dragdrop.js +974 -0
  67. data/fixtures/projects/rails-3/public/javascripts/effects.js +1123 -0
  68. data/fixtures/projects/rails-3/public/javascripts/prototype.js +6001 -0
  69. data/fixtures/projects/rails-3/public/javascripts/rails.js +175 -0
  70. data/fixtures/projects/rails-3/public/robots.txt +5 -0
  71. data/fixtures/projects/rails-3/public/stylesheets/.gitkeep +0 -0
  72. data/fixtures/projects/rails-3/script/rails +6 -0
  73. data/fixtures/projects/rails-3/test/performance/browsing_test.rb +9 -0
  74. data/fixtures/projects/rails-3/test/test_helper.rb +13 -0
  75. data/fixtures/projects/rails-3/vendor/plugins/.gitkeep +0 -0
  76. data/fixtures/projects/ruby/Gemfile +3 -0
  77. data/fixtures/projects/ruby/Gemfile.lock +10 -0
  78. data/fixtures/projects/ruby/Rakefile +4 -0
  79. data/jenkins.gemspec +34 -0
  80. data/lib/jenkins.rb +6 -0
  81. data/lib/jenkins/api.rb +312 -0
  82. data/lib/jenkins/cli.rb +361 -0
  83. data/lib/jenkins/cli/formatting.rb +53 -0
  84. data/lib/jenkins/config.rb +27 -0
  85. data/lib/jenkins/core_ext/hash.rb +9 -0
  86. data/lib/jenkins/core_ext/object/blank.rb +77 -0
  87. data/lib/jenkins/hudson-cli.jar +0 -0
  88. data/lib/jenkins/job_config_builder.rb +417 -0
  89. data/lib/jenkins/project_scm.rb +22 -0
  90. data/lib/jenkins/remote.rb +11 -0
  91. data/lib/jenkins/version.rb +3 -0
  92. data/spec/api_spec.rb +67 -0
  93. data/spec/fixtures/ec2_global.config.xml +103 -0
  94. data/spec/fixtures/erlang.single.config.xml +59 -0
  95. data/spec/fixtures/rails.multi.config.xml +82 -0
  96. data/spec/fixtures/rails.single.config.triggers.xml +84 -0
  97. data/spec/fixtures/rails.single.config.xml +80 -0
  98. data/spec/fixtures/ruby.multi-ruby-multi-labels.config.xml +84 -0
  99. data/spec/fixtures/ruby.multi.config.xml +77 -0
  100. data/spec/fixtures/ruby.single.config.xml +58 -0
  101. data/spec/fixtures/ruby.user-defined-axis.config.xml +69 -0
  102. data/spec/fixtures/therubyracer.config.xml +77 -0
  103. data/spec/hash_key_cleaner_spec.rb +25 -0
  104. data/spec/job_config_builder_spec.rb +233 -0
  105. data/spec/spec_helper.rb +15 -0
  106. metadata +291 -0
@@ -0,0 +1,361 @@
1
+ require 'thor'
2
+ require 'jenkins/core_ext/object/blank'
3
+ require 'jenkins/core_ext/hash'
4
+ require 'jenkins/cli/formatting'
5
+ require 'jenkins/remote'
6
+
7
+ # Until a new version (>= 0.14.6 & 0.15.0rc2) is released, this backports a fix
8
+ # for JRuby argument handling:
9
+ # https://github.com/wycats/thor/commit/33490a59ed297eb798381f1c86cbaa3608413eaf
10
+ class Thor
11
+ class Task
12
+ def sans_backtrace(backtrace, caller) #:nodoc:
13
+ saned = backtrace.reject { |frame| frame =~ FILE_REGEXP || (frame =~ /\.java:/ && RUBY_PLATFORM =~ /java/) }
14
+ saned -= caller
15
+ end
16
+ end
17
+ end
18
+
19
+
20
+ module Jenkins
21
+ class CLI < Thor
22
+ include CLI::Formatting
23
+
24
+ map "-v" => :version, "--version" => :version, "-h" => :help, "--help" => :help
25
+
26
+ def self.common_options
27
+ method_option :host, :desc => 'connect to jenkins server on this host'
28
+ method_option :port, :desc => 'connect to jenkins server on this port'
29
+ method_option :ssl, :desc => 'connect to jenkins server with ssl', :type => :boolean, :default => false
30
+ method_option :username, :desc => 'connect to jenkins server with username'
31
+ method_option :password, :desc => 'connect to jenkins server with password'
32
+ end
33
+
34
+ desc "server [options]", "run a jenkins server"
35
+ method_option :home, :desc => "use this directory to store server data", :type => :string, :default => File.join(ENV['HOME'], ".jenkins", "server"), :banner => "PATH"
36
+ method_option :port, :desc => "run jenkins server on this port", :type => :numeric, :default => 3001, :aliases => "-p"
37
+ method_option :control, :desc => "set the shutdown/control port", :type => :numeric, :default => 3002, :aliases => "-c"
38
+ method_option :daemon, :desc => "fork into background and run as a daemon", :type => :boolean, :default => false
39
+ method_option :kill, :desc => "send shutdown signal to control port", :type => :boolean, :aliases => "-k"
40
+ method_option :logfile, :desc => "redirect log messages to this file", :type => :string, :banner => "PATH"
41
+ def server
42
+ begin
43
+ require 'jenkins/war'
44
+ Jenkins::War::server(options)
45
+ rescue LoadError
46
+ puts "To run a jenkins server, you need to install the jenkins-war gem. try:"
47
+ puts "gem install jenkins-war"
48
+ end
49
+ end
50
+
51
+ desc "create project_path [options]", "create a build for your project"
52
+ common_options
53
+ method_option :rubies, :desc => "run tests against multiple explicit rubies via RVM", :type => :string
54
+ method_option :"node-labels", :desc => "run tests against multiple slave nodes by their label (comma separated)"
55
+ method_option :"assigned-node", :desc => "only use slave nodes with this label (similar to --node-labels)"
56
+ method_option :"no-build", :desc => "create job without initial build", :type => :boolean, :default => false
57
+ method_option :override, :desc => "override if job exists", :type => :boolean, :default => false
58
+ method_option :"scm", :desc => "specific SCM URI", :type => :string
59
+ method_option :"scm-branches", :desc => "list of branches to build from (comma separated)", :type => :string, :default => "master"
60
+ method_option :"public-scm", :desc => "use public scm URL", :type => :boolean, :default => false
61
+ method_option :template, :desc => "template of job steps (available: #{JobConfigBuilder::VALID_JOB_TEMPLATES.join ','})", :default => 'ruby'
62
+ method_option :"no-template", :desc => "do not use a template of default steps; avoids Gemfile requirement", :type => :boolean, :default => false
63
+ def create(project_path)
64
+ select_jenkins_server(options)
65
+ FileUtils.chdir(project_path) do
66
+ scm = discover_scm(options)
67
+ ruby_or_rails_project_without_gemfile?(options)
68
+ begin
69
+ template = options[:"no-template"] ? 'none' : options[:template]
70
+ job_config = build_job_config(scm, template, options)
71
+
72
+ if Jenkins::Api.create_job(project_name, job_config, options)
73
+ build_url = "#{@uri}/job/#{project_name.gsub(/\s/,'%20')}/build"
74
+ shell.say "Added#{' ' + template unless template == 'none'} project '#{project_name}' to Jenkins.", :green
75
+ unless options[:"no-build"]
76
+ shell.say "Triggering initial build..."
77
+ Jenkins::Api.build_job(project_name)
78
+ shell.say "Trigger additional builds via:"
79
+ else
80
+ shell.say "Trigger builds via:"
81
+ end
82
+ shell.say " URL: "; shell.say "#{build_url}", :yellow
83
+ shell.say " CLI: "; shell.say "#{cmd} build #{project_name}", :yellow
84
+ else
85
+ error "Failed to create project '#{project_name}'"
86
+ end
87
+ rescue Jenkins::JobConfigBuilder::InvalidTemplate
88
+ error "Invalid job template '#{template}'."
89
+ rescue Jenkins::Api::JobAlreadyExistsError
90
+ error "Job '#{project_name}' already exists."
91
+ end
92
+ end
93
+ end
94
+
95
+ desc "update project_path [options]", "update the configuration for your project"
96
+ common_options
97
+ method_option :rubies, :desc => "run tests against multiple explicit rubies via RVM", :type => :string
98
+ method_option :"node-labels", :desc => "run tests against multiple slave nodes by their label (comma separated)"
99
+ method_option :"assigned-node", :desc => "only use slave nodes with this label (similar to --node-labels)"
100
+ method_option :"no-build", :desc => "create job without initial build", :type => :boolean, :default => false
101
+ method_option :"scm", :desc => "specific SCM URI", :type => :string
102
+ method_option :"scm-branches", :desc => "list of branches to build from (comma separated)", :type => :string, :default => "master"
103
+ method_option :"public-scm", :desc => "use public scm URL", :type => :boolean, :default => false
104
+ method_option :template, :desc => "template of job steps (available: #{JobConfigBuilder::VALID_JOB_TEMPLATES.join ','})", :default => 'ruby'
105
+ method_option :"no-template", :desc => "do not use a template of default steps; avoids Gemfile requirement", :type => :boolean, :default => false
106
+ def update(project_path)
107
+ select_jenkins_server(options)
108
+ FileUtils.chdir(project_path) do
109
+ scm = discover_scm(options)
110
+ ruby_or_rails_project_without_gemfile?(options)
111
+ begin
112
+ template = options[:"no-template"] ? 'none' : options[:template]
113
+ job_config = build_job_config(scm, template, options)
114
+
115
+ if Jenkins::Api.update_job(project_name, job_config)
116
+ shell.say "Updated#{' ' + template unless template == 'none'} project '#{project_name}'.", :green
117
+ else
118
+ error "Failed to update project '#{project_name}'"
119
+ end
120
+ rescue Jenkins::JobConfigBuilder::InvalidTemplate
121
+ error "Invalid job template '#{template}'."
122
+ end
123
+ end
124
+ end
125
+
126
+ desc "build [PROJECT_PATH]", "trigger build of this project's build job"
127
+ common_options
128
+ def build(project_path = ".")
129
+ select_jenkins_server(options)
130
+ FileUtils.chdir(project_path) do
131
+ if Jenkins::Api.build_job(project_name)
132
+ shell.say "Build for '#{project_name}' running now..."
133
+ else
134
+ error "No job '#{project_name}' on server."
135
+ end
136
+ end
137
+ end
138
+
139
+ desc "remove PROJECT_PATH", "remove this project's build job from Jenkins"
140
+ common_options
141
+ def remove(project_path)
142
+ select_jenkins_server(options)
143
+ FileUtils.chdir(project_path) do
144
+ if Jenkins::Api.delete_job(project_name)
145
+ shell.say "Removed project '#{project_name}' from Jenkins."
146
+ else
147
+ error "Failed to delete project '#{project_name}'."
148
+ end
149
+ end
150
+ end
151
+
152
+ desc "job NAME", "Display job details"
153
+ method_option :hash, :desc => 'Dump as formatted Ruby hash format'
154
+ method_option :json, :desc => 'Dump as JSON format'
155
+ method_option :yaml, :desc => 'Dump as YAML format'
156
+ common_options
157
+ def job(name)
158
+ select_jenkins_server(options)
159
+ if job = Jenkins::Api.job(name)
160
+ if options[:hash]
161
+ require "ap"
162
+ ap job.parsed_response
163
+ elsif options[:json]
164
+ puts job.parsed_response.to_json
165
+ elsif options[:yaml]
166
+ require "yaml"
167
+ puts job.parsed_response.to_yaml
168
+ else
169
+ error "Select an output format: --json, --yaml, --hash"
170
+ end
171
+ else
172
+ error "Cannot find project '#{name}'."
173
+ end
174
+ end
175
+
176
+ desc "build_details JOB_NAME BUILD_NUMBER", "Display details about a particular build"
177
+ method_option :hash, :desc => 'Dump as formatted Ruby hash format'
178
+ method_option :json, :desc => 'Dump as JSON format'
179
+ method_option :yaml, :desc => 'Dump as YAML format'
180
+ common_options
181
+ def build_details(job_name, build_number="lastBuild")
182
+ select_jenkins_server(options)
183
+ if build_details = Jenkins::Api.build_details(job_name, build_number)
184
+ if options[:hash]
185
+ require "ap"
186
+ ap build_details.parsed_response
187
+ elsif options[:json]
188
+ puts build_details.parsed_response.to_json
189
+ elsif options[:yaml]
190
+ require "yaml"
191
+ puts build_details.parsed_response.to_yaml
192
+ else
193
+ error "Select an output format: --json, --yaml, --hash"
194
+ end
195
+ else
196
+ error "Cannot find project '#{job_name}'."
197
+ end
198
+ end
199
+
200
+ desc "console JOB_NAME BUILD_NUMBER [AXE]", "Display the console"
201
+ common_options
202
+ def console(job_name, axe=nil, build_number="lastBuild")
203
+ select_jenkins_server(options)
204
+ puts Jenkins::Api.console(job_name, build_number, axe)
205
+ end
206
+
207
+ desc "list [options]", "list jobs on a jenkins server"
208
+ common_options
209
+ def list
210
+ select_jenkins_server(options)
211
+ summary = Jenkins::Api.summary
212
+ unless summary["jobs"].blank?
213
+ shell.say "#{@uri}:", :bold
214
+ summary["jobs"].each do |job|
215
+ bold = job['color'] =~ /anime/
216
+ color = 'red' if job['color'] =~ /red/
217
+ color = 'green' if job['color'] =~ /(blue|green)/
218
+ color ||= 'yellow' # if color =~ /grey/ || color == 'disabled'
219
+ shell.say "* "; shell.say(shell.set_color(job['name'], color.to_sym, bold), nil, true)
220
+ end
221
+ shell.say ""
222
+ else
223
+ shell.say "#{@uri}: "; shell.say "no jobs", :yellow
224
+ end
225
+ end
226
+
227
+ desc "nodes", "list jenkins server nodes"
228
+ common_options
229
+ def nodes
230
+ select_jenkins_server(options)
231
+ nodes = Jenkins::Api.nodes
232
+ nodes["computer"].each do |node|
233
+ color = node["offline"] ? :red : :green
234
+ shell.say node["displayName"], color
235
+ end
236
+ end
237
+
238
+ desc "add_node SLAVE_HOST", "add a URI (user@host:port) server as a slave node"
239
+ method_option :labels, :desc => 'Labels for a job --assigned_node to match against to select a slave (comma separated)'
240
+ method_option :"slave-user", :desc => 'SSH user for Jenkins to connect to slave node (default: deploy)'
241
+ method_option :"slave-port", :desc => 'SSH port for Jenkins to connect to slave node (default: 22)'
242
+ method_option :"master-key", :desc => 'Location of master public key or identity file'
243
+ method_option :"slave-fs", :desc => 'Location of file system on slave for Jenkins to use'
244
+ method_option :name, :desc => 'Name of slave node (default SLAVE_HOST)'
245
+ method_option :vagrant, :desc => 'Use settings for a Vagrant VM', :type => :boolean, :default => false
246
+ common_options
247
+ def add_node(slave_host)
248
+ select_jenkins_server(options)
249
+ if results = Jenkins::Api.add_node({:slave_host => slave_host}.merge(options))
250
+ shell.say "Added slave node '#{results[:name]}' to #{results[:slave_host]}", :green
251
+ else
252
+ error "Failed to add slave node #{slave_host}"
253
+ end
254
+ end
255
+
256
+ desc "default_host", "display current default host:port URI"
257
+ def default_host
258
+ if select_jenkins_server({})
259
+ display Jenkins::Api.base_uri
260
+ else
261
+ display "No default host yet. Use '--host host --port port' on your first request."
262
+ end
263
+ end
264
+
265
+ desc "configure", "configure host connection information"
266
+ common_options
267
+ def configure
268
+ Jenkins::Api.setup_base_url(options)
269
+ Jenkins::Api.cache_configuration!
270
+ end
271
+
272
+ desc "auth_info", "display authentication information"
273
+ def auth_info
274
+ if auth = Jenkins::Config.config['basic_auth']
275
+ shell.say "username: #{auth["username"]}"
276
+ shell.say "password: #{auth["password"]}"
277
+ end
278
+ end
279
+
280
+ desc "help [command]", "show help for jenkins or for a specific command"
281
+ def help(*args)
282
+ super(*args)
283
+ end
284
+
285
+ desc "version", "show version information"
286
+ def version
287
+ shell.say "#{Jenkins::VERSION}"
288
+ end
289
+
290
+ def self.help(shell, *)
291
+ list = printable_tasks
292
+ shell.say <<-USEAGE
293
+ Jenkins.rb is a smart set of utilities for making
294
+ continuous integration as simple as possible
295
+
296
+ Usage: jenkins command [arguments] [options]
297
+
298
+ USEAGE
299
+
300
+ shell.say "Commands:"
301
+ shell.print_table(list, :ident => 2, :truncate => true)
302
+ shell.say
303
+ class_options_help(shell)
304
+ end
305
+
306
+ private
307
+
308
+ def method_missing(name, *args)
309
+ console(name, *args)
310
+ end
311
+
312
+ def select_jenkins_server(options)
313
+ unless @uri = Jenkins::Api.setup_base_url(options)
314
+ error "Either use --host or add remote servers."
315
+ end
316
+ @uri
317
+ end
318
+
319
+ def display(text)
320
+ shell.say text
321
+ exit
322
+ end
323
+
324
+ def error(text)
325
+ shell.say "ERROR: #{text}", :red
326
+ exit
327
+ end
328
+
329
+ def cmd
330
+ ENV['CUCUMBER_RUNNING'] ? 'jenkins' : $0
331
+ end
332
+
333
+ def project_name
334
+ @project_name ||= File.basename(FileUtils.pwd)
335
+ end
336
+
337
+ def build_job_config(scm, template, options)
338
+ Jenkins::JobConfigBuilder.new(template) do |c|
339
+ c.rubies = options[:rubies].split(/\s*,\s*/) if options[:rubies]
340
+ c.node_labels = options[:"node-labels"].split(/\s*,\s*/) if options[:"node-labels"]
341
+ c.scm = scm.url
342
+ c.scm_branches = options[:"scm-branches"].split(/\s*,\s*/)
343
+ c.assigned_node = options[:"assigned-node"] if options[:"assigned-node"]
344
+ c.public_scm = options[:"public-scm"]
345
+ end
346
+ end
347
+
348
+ def ruby_or_rails_project_without_gemfile?(options)
349
+ unless (options[:template] == "none" || options[:template] == "erlang" || options[:"no-template"]) || File.exists?("Gemfile")
350
+ error "Ruby/Rails projects without a Gemfile are currently unsupported."
351
+ end
352
+ end
353
+
354
+ def discover_scm(options)
355
+ unless scm = Jenkins::ProjectScm.discover(options[:scm])
356
+ error "Cannot determine project SCM. Currently supported: #{Jenkins::ProjectScm.supported}"
357
+ end
358
+ scm
359
+ end
360
+ end
361
+ end
@@ -0,0 +1,53 @@
1
+ require 'term/ansicolor'
2
+
3
+ module Jenkins
4
+ class CLI < Thor
5
+ module Formatting
6
+ module ClassMethods
7
+ def task_help(shell, task_name)
8
+ meth = normalize_task_name(task_name)
9
+ task = all_tasks[meth]
10
+ handle_no_task_error(meth) unless task
11
+
12
+ shell.say "usage: #{banner(task)}"
13
+ shell.say
14
+ class_options_help(shell, nil => task.options.map { |_, o| o })
15
+ # shell.say task.description
16
+ # shell.say
17
+ end
18
+
19
+
20
+ def print_options(shell, options, grp = nil)
21
+ return if options.empty?
22
+ table = options.map do |option|
23
+ prototype = if option.default
24
+ " [#{option.default}]"
25
+ elsif option.boolean?
26
+ ""
27
+ elsif option.required?
28
+ " #{option.banner}"
29
+ else
30
+ " [#{option.banner}]"
31
+ end
32
+ aliases = option.aliases.empty? ? "" : option.aliases.join(" ") + ","
33
+ [aliases, "--#{option.name}#{prototype}", "\t",option.description]
34
+ end
35
+ shell.print_table(table, :ident => 2)
36
+ shell.say
37
+ end
38
+ end
39
+
40
+ module InstanceMethods
41
+ def c
42
+ Term::ANSIColor
43
+ end
44
+ end
45
+
46
+ def self.included(receiver)
47
+ receiver.extend ClassMethods
48
+ receiver.send :include, InstanceMethods
49
+ end
50
+ end
51
+ end
52
+ end
53
+
@@ -0,0 +1,27 @@
1
+ module Jenkins
2
+ module Config
3
+ extend self
4
+
5
+ def [](key)
6
+ config[key]
7
+ end
8
+
9
+ def config
10
+ @config ||= if File.exist?(config_file)
11
+ JSON.parse(File.read(config_file))
12
+ else
13
+ {}
14
+ end
15
+ end
16
+
17
+ def store!
18
+ @config ||= {}
19
+ FileUtils.mkdir_p(File.dirname(config_file))
20
+ File.open(config_file, "w") { |file| file << @config.to_json }
21
+ end
22
+
23
+ def config_file
24
+ @config_file ||= "#{ENV['HOME']}/.jenkins/jenkinsrb-config.json"
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,9 @@
1
+ class Hash
2
+ def with_clean_keys
3
+ self.inject({}) do |mem, (key, value)|
4
+ clean_key = key.to_s.gsub(/-/,"_").to_sym
5
+ mem[clean_key] = value
6
+ mem
7
+ end
8
+ end
9
+ end