puppet 2.7.22 → 2.7.23

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of puppet might be problematic. Click here for more details.

Files changed (55) hide show
  1. data/CHANGELOG +21 -0
  2. data/Rakefile +0 -2
  3. data/ext/build_defaults.yaml +1 -1
  4. data/ext/packaging/README.md +88 -33
  5. data/ext/packaging/packaging.rake +45 -0
  6. data/ext/packaging/spec/tasks/build_object_spec.rb +2 -0
  7. data/ext/packaging/tasks/00_utils.rake +94 -54
  8. data/ext/packaging/tasks/10_setupvars.rake +40 -28
  9. data/ext/packaging/tasks/apple.rake +20 -27
  10. data/ext/packaging/tasks/build.rake +3 -8
  11. data/ext/packaging/tasks/deb.rake +12 -36
  12. data/ext/packaging/tasks/deb_repos.rake +28 -36
  13. data/ext/packaging/tasks/fetch.rake +1 -2
  14. data/ext/packaging/tasks/jenkins.rake +22 -56
  15. data/ext/packaging/tasks/jenkins_dynamic.rake +111 -0
  16. data/ext/packaging/tasks/mock.rake +101 -56
  17. data/ext/packaging/tasks/pe_deb.rake +5 -7
  18. data/ext/packaging/tasks/pe_remote.rake +30 -42
  19. data/ext/packaging/tasks/pe_rpm.rake +3 -11
  20. data/ext/packaging/tasks/pe_ship.rake +14 -18
  21. data/ext/packaging/tasks/pe_sign.rake +11 -0
  22. data/ext/packaging/tasks/pe_tar.rake +1 -1
  23. data/ext/packaging/tasks/release.rake +0 -6
  24. data/ext/packaging/tasks/remote_build.rake +1 -13
  25. data/ext/packaging/tasks/retrieve.rake +1 -1
  26. data/ext/packaging/tasks/rpm.rake +15 -10
  27. data/ext/packaging/tasks/rpm_repos.rake +45 -56
  28. data/ext/packaging/tasks/ship.rake +46 -37
  29. data/ext/packaging/tasks/sign.rake +22 -14
  30. data/ext/packaging/tasks/tar.rake +1 -1
  31. data/ext/packaging/tasks/template.rake +1 -1
  32. data/ext/packaging/templates/README +1 -0
  33. data/ext/packaging/templates/downstream.xml.erb +32 -0
  34. data/ext/packaging/templates/packaging.xml.erb +182 -0
  35. data/ext/packaging/templates/repo.xml.erb +93 -0
  36. data/lib/puppet.rb +2 -0
  37. data/lib/puppet/file_system.rb +3 -0
  38. data/lib/puppet/file_system/path_pattern.rb +97 -0
  39. data/lib/puppet/module.rb +25 -4
  40. data/lib/puppet/module_tool/applications/unpacker.rb +5 -1
  41. data/lib/puppet/parser/files.rb +20 -15
  42. data/lib/puppet/parser/parser_support.rb +10 -1
  43. data/lib/puppet/parser/type_loader.rb +48 -28
  44. data/lib/puppet/version.rb +1 -1
  45. data/spec/unit/file_system/path_pattern_spec.rb +139 -0
  46. data/spec/unit/module_spec.rb +8 -1
  47. data/spec/unit/module_tool/applications/unpacker_spec.rb +6 -0
  48. data/spec/unit/parser/files_spec.rb +6 -67
  49. data/spec/unit/parser/parser_spec.rb +15 -5
  50. data/spec/unit/parser/type_loader_spec.rb +14 -33
  51. data/spec/unit/resource/type_collection_spec.rb +39 -55
  52. metadata +11 -5
  53. data/Gemfile.lock +0 -44
  54. data/ext/packaging/tasks/pe_sles.rake +0 -101
  55. data/ext/packaging/tasks/pre_tasks.rake +0 -0
data/CHANGELOG CHANGED
@@ -1,3 +1,24 @@
1
+ 2.7.23
2
+ ===
3
+ 4295e3d (maint) Fix module_utils regex tests for module file perms
4
+ a322f34 (Maint) Update test to reflect chown using the gid too
5
+ 28bda0f (Maint) Update expectations for older rspec
6
+ be2d182 Improving testing around PMT module install permissions.
7
+ 7114934 Ensure that PMT uses the correct group membership.
8
+ 64d2637 (#21971) Allow paths that contain .. as part of a name
9
+ d88dd3f (Maint) Confine module tool tests off of windows
10
+ 9e5ef53 Fixing broken requires in the acceptance tests.
11
+ 878c420 (#21971) Fixes PathPattern's usage of Dir.glob for Windows
12
+ 2455fac (#21971) Fix how import_all loads files
13
+ 7a13291 (#21971) Create system for safely dealing with path patterns
14
+ 3c8dc4a (#21971) Split import and autoloading code paths
15
+ 0a35ef4 (#21971) Check for possible directory traversal
16
+ 30a72ce (Maint) Clean up specs
17
+ c3d1703 (Maint) Use dirname instead of regexes
18
+ f02f186 Backporting acceptance tests.
19
+ 90d4180 (#14333) Ensure module permissions are sane.
20
+
21
+
1
22
  2.7.22
2
23
  ===
3
24
  ba8c021 [packaging] Update mocks for rpmbuilder mock format
data/Rakefile CHANGED
@@ -9,8 +9,6 @@ $LOAD_PATH << File.join(File.dirname(__FILE__), 'tasks')
9
9
  begin
10
10
  require 'rubygems'
11
11
  require 'rubygems/package_task'
12
- require 'rspec'
13
- require 'rspec/core/rake_task'
14
12
  rescue LoadError
15
13
  # Users of older versions of Rake (0.8.7 for example) will not necessarily
16
14
  # have rubygems installed, or the newer rubygems package_task for that
@@ -2,7 +2,7 @@
2
2
  packaging_url: 'git://github.com/puppetlabs/packaging.git --branch=master'
3
3
  packaging_repo: 'packaging'
4
4
  default_cow: 'base-squeeze-i386.cow'
5
- cows: 'base-lucid-i386.cow base-oneiric-i386.cow base-precise-i386.cow base-quantal-i386.cow base-sid-i386.cow base-squeeze-i386.cow base-stable-i386.cow base-testing-i386.cow base-unstable-i386.cow base-wheezy-i386.cow'
5
+ cows: 'base-lucid-i386.cow base-precise-i386.cow base-quantal-i386.cow base-sid-i386.cow base-squeeze-i386.cow base-stable-i386.cow base-testing-i386.cow base-unstable-i386.cow base-wheezy-i386.cow'
6
6
  pbuild_conf: '/etc/pbuilderrc'
7
7
  packager: 'puppetlabs'
8
8
  gpg_name: 'info@puppetlabs.com'
@@ -89,11 +89,7 @@ for developer use for building test packages; the `pe:deb` task creates a
89
89
  `ext/build_defaults.yaml` after `final_mocks:`. For PE, the mocks are
90
90
  formatted as `pupent-<peversion>-<distversion>-<arch>`, e.g.
91
91
  `pupent-2.7-el5-i386`. To build for a specific target, set `MOCK=<mock>` to
92
- the mock that matches the target. The `pe:deb` and `pe:mock` tasks work by
93
- using the `:remote` tasks for building on a remote builder using the current
94
- committed state of the source repository. To forego remote building and build
95
- on the local station (e.g., by ssh-ing into a remote builder first), the
96
- tasks `pe:local_mock` and `pe:local_deb` build using the local host.
92
+ the mock that matches the target.
97
93
 
98
94
  ## `:remote:` tasks
99
95
  There are also sub-namespaces of `:pl` and `:pe` that are
@@ -132,10 +128,12 @@ Jenkins tasks are similar to the `:remote:` tasks, but they do not require ssh
132
128
  access to the builders. They do require being on the local network - the
133
129
  jenkins instance that performs package builds is an internal server only,
134
130
  accessible when connected via VPN or on-site. The jenkins tasks enable the
135
- packaging repo to kick off packaging builds on a remote jenkins slave. They
136
- work in a similar way to the :remote tasks, but with a few key differences. The
137
- jenkins tasks transmit information to a jenkins coordinator, which handles the
138
- rest. The data passed are the following:
131
+ packaging repo to kick off packaging builds on a remote jenkins slave.
132
+ There are two workflows of jenkins tasks in the packaging repo. The first
133
+ workflow, which is used for creating individual platform packages on jenkins
134
+ (e.g. creating a deb with pl:jenkins:deb) relies on a job that exists on a
135
+ remote jenkins server. The tasks transmit information to the jenkins job, which
136
+ handles the rest. The data passed are the following:
139
137
 
140
138
  1) $PROJECT\_BUNDLE - a tar.gz of a git-bundle from HEAD of the current
141
139
  project, which is cloned on the builder to set up a duplicate of this
@@ -208,10 +206,63 @@ the task are:
208
206
 
209
207
  #################
210
208
  ```
209
+ The second, more recent, jenkins-based workflow is for initiating the
210
+ "uber_build", or a package build for all of our target platforms. This workflow
211
+ doesn't actually use a static job on the jenkins-server. Instead it _creates_
212
+ the jenkins jobs for you, on-demand. Specifically, it creates two jenkins-jobs,
213
+ and can create an optional third.
214
+
215
+ The first job is a matrix job, the cells of which are individual package tasks
216
+ for all of the build targets. This job takes three parameters:
217
+
218
+ 1) $PROJECT\_BUNDLE - a tar.gz of a git-bundle from HEAD of the current
219
+ project, which is cloned on the builder to set up a duplicate of this
220
+ environment
221
+
222
+ 2) $BUILD\_PROPERTIES - a build parameters file, containing all information
223
+ about the build
224
+
225
+ 3) $PROJECT - the project we're building, e.g. facter, puppet. This is used
226
+ later in determining the target for the build artifacts on the distribution
227
+ server
228
+
229
+ This first job clones the git bundle passed in as a parameter, then clones the
230
+ packaging repo (rake package:bootstrap) and for every cell in its matrix
231
+ performs a package build for a specific target (e.g. rake pl:deb
232
+ COW=base-lucid-i386.cow). If all cells in the matrix complete successfully (if
233
+ all packages build), this job automatically triggers the second of the new jobs
234
+ as a downstream job.
235
+
236
+ To receive an email notification from jenkins about the status of the packaging
237
+ job, pass NOTIFY=<recipient> as an environment variable to the uber_build
238
+ invocation, e.g.:
239
+
240
+ rake pl:jenkins:uber_build NOTIFY="foo@puppetlabs.com bar@puppetlabs.com"
241
+
242
+ The second job is an automatic repository creation task for this git repo.
243
+ Specifically, the job copies the git bundle from the packaging job and clones
244
+ it, and uses the git information in the git bundle to clone the packaging repo
245
+ and invoke the repository creation jobs `pl:jenkins:rpm_repos` and
246
+ `pl:jenkins:deb_repos`.
247
+
248
+ The third job is only created _if_ the environment variable
249
+ `DOWNSTREAM_JOB=<job_url>` was passed to the initial "pl:jenkins:uber_build"
250
+ invocation. This third job takes the value assigned to `DOWNSTREAM_JOB` and
251
+ creates a proxy jenkins job with a single build step, a curl call to this
252
+ value, presumably a url to a jenkins job to trigger programmatically.
253
+ Once the repos have successfully been created by the second job, the third job
254
+ will automatically trigger as a downstream job.
255
+
256
+ All 3 jobs are configured by default for removal by jenkins after 3 days, to
257
+ avoid clutter.
258
+
259
+ The goal is to move toward migrating all of the jenkins tasks from the first
260
+ workflow, using a static job that is called many times per package, to this
261
+ second workflow of creating the jobs on demand.
211
262
 
212
263
  ## Task Explanations
213
264
  For a listing of all available tasks and their functions, see the [Task
214
- Dictionary](https://github.com/MosesMendoza/packaging/tree/more_documentation#task-dictionary)
265
+ Dictionary](https://github.com/puppetlabs/packaging/tree/more_documentation#task-dictionary)
215
266
  at the end of this README.
216
267
 
217
268
  ## Modules
@@ -301,15 +352,17 @@ sign_tar: FALSE
301
352
  # a space separated list of mock configs. These are the rpm distributions to package for. If a noarch package, only one arch of each is needed.
302
353
  final_mocks: 'pl-el-5-i386 pl-el-5-x86_64 pl-el-6-i386 pl-el-6-x86_64 pl-fedora-16-i386 pl-fedora-16-x86_64 pl-fedora-17-i386 pl-fedora-17-x86_64'
303
354
  # The host that contains the yum repository to ship to
304
- yum_host: 'burji.puppetlabs.com'
355
+ yum_host: 'yum.puppetlabs.com'
305
356
  # The remote path the repository on the yum\_host
306
357
  yum_repo_path: '/some/repo/'
307
358
  # The host that contains the apt repository to ship to
308
- apt_host: 'burji.puppetlabs.com'
359
+ apt_host: 'apt.puppetlabs.com'
309
360
  # The URL to use for the apt dependencies in cow building
310
361
  apt_repo_url: 'http://apt.puppetlabs.com'
311
362
  # The path on the remote apt host that debs should ship to
312
363
  apt_repo_path: '/opt/repository/incoming'
364
+ # The host that stores the tarballs for downloading
365
+ tar_host: 'downloads.puppetlabs.com'
313
366
  # Whether to present the gem and apple tasks
314
367
  build_gem: TRUE
315
368
  build_dmg: TRUE
@@ -678,10 +731,12 @@ files:
678
731
 
679
732
  * **pl:jenkins:uber_build**
680
733
 
681
- An aggregate of build tasks. These include `jenkins:deb_all`,
682
- `pl:jenkins:mock_all`, `pl:jenkins:tar`, `pl:jenkins:dmg`, and `pl:jenkins:gem`. Each
683
- task is a separate job that is posted to the jenkins build server,
684
- separated by a 5 second sleep.
734
+ Create a jenkins job on the fly that performs an aggregate of build tasks.
735
+ These include all the debian builds using `pl:deb COW=<cow>`, rpm builds
736
+ with `pl:mock MOCKS=<mock>`, `package:tar`, `package:apple`, and
737
+ `package:gem` if applicable. See
738
+ [jenkins-tasks](https://github.com/puppetlabs/packaging#jenkins-tasks)
739
+ above for more detail.
685
740
 
686
741
  * **pl:jenkins:uber_ship**
687
742
 
@@ -868,16 +923,16 @@ files:
868
923
 
869
924
  * **pl:uber_release**
870
925
 
871
- A composite task that performs the following tasks:
872
- `package:gem` (if build_gem is "true" in build_defaults.yaml)
873
- `pl:remote:release_deb`
874
- `pl:remote:release_rpm`
875
- `pl:remote:dmg` (if build_dmg is "true" in build_defaults.yaml)
876
- `package:tar`
877
- `pl:sign_tar`
878
- `pl:uber_ship`
879
- `pl:remote:freight`
880
- `pl:remote:update_yum_repo`
926
+ A composite task that performs the following tasks:
927
+ `package:gem` (if build_gem is "true" in build_defaults.yaml)
928
+ `pl:remote:release_deb`
929
+ `pl:remote:release_rpm`
930
+ `pl:remote:dmg` (if build_dmg is "true" in build_defaults.yaml)
931
+ `package:tar`
932
+ `pl:sign_tar`
933
+ `pl:uber_ship`
934
+ `pl:remote:freight`
935
+ `pl:remote:update_yum_repo`
881
936
  This is essentially a complete build from start to finish. Gem and tarball
882
937
  are generated locally, and other packages (deb, rpm, dmg) are all created
883
938
  remotely. Assumes ssh access and appropriate build tool access on all
@@ -885,13 +940,13 @@ files:
885
940
 
886
941
  * **pl:uber_ship**
887
942
 
888
- A composite task that performs the following tasks:
889
- `pl:ship_gem`
890
- `pl:ship_rpms`
891
- `pl:ship_debs`
892
- `pl:ship_dmgs`
893
- `pl:ship_tar`
894
- `pl:jenkins:ship`
943
+ A composite task that performs the following tasks:
944
+ `pl:ship_gem`
945
+ `pl:ship_rpms`
946
+ `pl:ship_debs`
947
+ `pl:ship_dmgs`
948
+ `pl:ship_tar`
949
+ `pl:jenkins:ship`
895
950
  This is essentially a "ship all the things" task, but it is important to
896
951
  note that it does not update either yum or apt repo metadata on these
897
952
  respective servers - this has to be done via `pl:remote:update_yum_repo`
@@ -0,0 +1,45 @@
1
+ # Load packaging repo tasks
2
+
3
+ # These are ordered
4
+
5
+ PACKAGING_PATH = File.join(File.dirname(__FILE__), 'tasks')
6
+
7
+ @using_loader = true
8
+
9
+ [ '00_utils.rake',
10
+ '10_setupvars.rake',
11
+ '20_setupextravars.rake',
12
+ '30_metrics.rake',
13
+ 'apple.rake',
14
+ 'build.rake',
15
+ 'clean.rake',
16
+ 'deb.rake',
17
+ 'deb_repos.rake',
18
+ 'doc.rake',
19
+ 'fetch.rake',
20
+ 'gem.rake',
21
+ 'ips.rake',
22
+ 'jenkins.rake',
23
+ 'jenkins_dynamic.rake',
24
+ 'mock.rake',
25
+ 'pe_deb.rake',
26
+ 'pe_remote.rake',
27
+ 'pe_rpm.rake',
28
+ 'pe_ship.rake',
29
+ 'pe_sign.rake',
30
+ 'pe_tar.rake',
31
+ 'release.rake',
32
+ 'remote_build.rake',
33
+ 'retrieve.rake',
34
+ 'rpm.rake',
35
+ 'rpm_repos.rake',
36
+ 'ship.rake',
37
+ 'sign.rake',
38
+ 'tag.rake',
39
+ 'tar.rake',
40
+ 'template.rake',
41
+ 'update.rake',
42
+ 'vendor_gems.rake',
43
+ 'version.rake',
44
+ 'z_data_dump.rake'].each { |t| load File.join(PACKAGING_PATH, t)}
45
+
@@ -10,6 +10,7 @@ describe Build::BuildInstance do
10
10
  :apt_repo_url,
11
11
  :author,
12
12
  :benchmark,
13
+ :build_date,
13
14
  :build_defaults,
14
15
  :build_dmg,
15
16
  :build_doc,
@@ -62,6 +63,7 @@ describe Build::BuildInstance do
62
63
  :jenkins_repo_path,
63
64
  :metrics,
64
65
  :name,
66
+ :notify,
65
67
  :project,
66
68
  :origversion,
67
69
  :osx_build_host,
@@ -2,8 +2,7 @@
2
2
 
3
3
  def check_tool(tool)
4
4
  return true if has_tool(tool)
5
- STDERR.puts "#{tool} tool not found...exiting"
6
- exit 1
5
+ fail "#{tool} tool not found...exiting"
7
6
  end
8
7
 
9
8
  def find_tool(tool)
@@ -16,31 +15,25 @@ end
16
15
  alias :has_tool :find_tool
17
16
 
18
17
  def check_file(file)
19
- unless File.exist?(file)
20
- STDERR.puts "#{file} file not found...exiting"
21
- exit 2
22
- end
18
+ File.exist?(file) or fail "#{file} file not found!"
23
19
  end
24
20
 
25
21
  def check_var(varname,var=nil)
26
- if var.nil?
27
- STDERR.puts "Requires #{varname} be set...exiting"
28
- exit 3
29
- end
22
+ var.nil? and fail "Requires #{varname} be set!"
30
23
  end
31
24
 
32
25
  def check_host(host)
33
- unless host == %x{hostname}.chomp!
34
- STDERR.puts "Requires host to be #{host}...exiting"
35
- exit 5
36
- end
26
+ host == %x{hostname}.chomp! or fail "Requires host to be #{host}!"
27
+ end
28
+
29
+ def erb_string(erbfile)
30
+ template = File.read(erbfile)
31
+ message = ERB.new(template, nil, "-")
32
+ message.result(binding)
37
33
  end
38
34
 
39
35
  def erb(erbfile, outfile)
40
- template = File.read(erbfile)
41
- message = ERB.new(template, nil, "-")
42
- message.filename = erbfile
43
- output = message.result(binding)
36
+ output = erb_string(erbfile)
44
37
  File.open(outfile, 'w') { |f| f.write output }
45
38
  puts "Generated: #{outfile}"
46
39
  end
@@ -56,16 +49,13 @@ def cp_p(src, dest, options={})
56
49
  end
57
50
 
58
51
  def mv_f(src, dest, options={})
59
- force = {:force => true}
52
+ mandatory = {:force => true}
60
53
  mv(src, dest, options.merge(mandatory))
61
54
  end
62
55
 
63
56
  def git_co(ref)
64
57
  %x{git reset --hard ; git checkout #{ref}}
65
- unless $?.success?
66
- STDERR.puts "Could not checkout #{ref} git branch to build package from...exiting"
67
- exit 1
68
- end
58
+ $?.success? or fail "Could not checkout #{ref} git branch to build package from...exiting"
69
59
  end
70
60
 
71
61
  def git_describe
@@ -92,7 +82,7 @@ def git_sha_or_tag
92
82
  end
93
83
 
94
84
  def get_temp
95
- temp = `mktemp -d -t pkgXXXXXX`.strip
85
+ `mktemp -d -t pkgXXXXXX`.strip
96
86
  end
97
87
 
98
88
  def remote_ssh_cmd target, command
@@ -103,7 +93,7 @@ end
103
93
 
104
94
  def rsync_to *args
105
95
  check_tool('rsync')
106
- flags = "-Havxl -O --no-perms --no-owner --no-group"
96
+ flags = "-rHlv -O --no-perms --no-owner --no-group"
107
97
  source = args[0]
108
98
  target = args[1]
109
99
  dest = args[2]
@@ -113,7 +103,7 @@ end
113
103
 
114
104
  def rsync_from *args
115
105
  check_tool('rsync')
116
- flags = "-Havxl -O --no-perms --no-owner --no-group"
106
+ flags = "-rHlv -O --no-perms --no-owner --no-group"
117
107
  source = args[0]
118
108
  target = args[1]
119
109
  dest = args[2]
@@ -129,8 +119,13 @@ def scp_file_to(host,path,file)
129
119
  %x{scp #{@tempdir}/#{file} #{host}:#{path}}
130
120
  end
131
121
 
132
- def timestamp
133
- Time.now.strftime("%Y-%m-%d %H:%M:%S")
122
+ def timestamp(separator=nil)
123
+ if s = separator
124
+ format = "%Y#{s}%m#{s}%d#{s}%H#{s}%M#{s}%S"
125
+ else
126
+ format = "%Y-%m-%d %H:%M:%S"
127
+ end
128
+ Time.now.strftime(format)
134
129
  end
135
130
 
136
131
  # Return information about the current tree, using `git describe`, ready for
@@ -243,6 +238,14 @@ def source_dirty?
243
238
  git_describe_version.include?('dirty')
244
239
  end
245
240
 
241
+ def fail_on_dirty_source
242
+ if source_dirty?
243
+ fail "
244
+ The source tree is dirty, e.g. there are uncommited changes. Please
245
+ commit/discard changes and try again."
246
+ end
247
+ end
248
+
246
249
  def kill_keychain
247
250
  %x{keychain -k mine}
248
251
  end
@@ -259,8 +262,7 @@ def gpg_sign_file(file)
259
262
  if gpg
260
263
  sh "#{gpg} --armor --detach-sign -u #{@build.gpg_key} #{file}"
261
264
  else
262
- STDERR.puts "No gpg available. Cannot sign #{file}. Exiting..."
263
- exit 1
265
+ fail "No gpg available. Cannot sign #{file}."
264
266
  end
265
267
  end
266
268
 
@@ -273,14 +275,12 @@ end
273
275
  def set_cow_envs(cow)
274
276
  elements = cow.split('-')
275
277
  if elements.size != 3
276
- STDERR.puts "Expecting a cow name split on hyphens, e.g. 'base-squeeze-i386'"
277
- exit 1
278
+ fail "Expecting a cow name split on hyphens, e.g. 'base-squeeze-i386'"
278
279
  else
279
280
  dist = elements[1]
280
281
  arch = elements[2]
281
282
  if dist.nil? or arch.nil?
282
- STDERR.puts "Couldn't get the arg and dist from cow name. Expecting something like 'base-dist-arch'"
283
- exit 1
283
+ fail "Couldn't get the arg and dist from cow name. Expecting something like 'base-dist-arch'"
284
284
  end
285
285
  arch = arch.split('.')[0] if arch.include?('.')
286
286
  end
@@ -352,13 +352,8 @@ def boolean_value(var)
352
352
  end
353
353
 
354
354
  def git_tag(version)
355
- begin
356
- sh "git tag -s -u #{@build.gpg_key} -m '#{version}' #{version}"
357
- rescue Exception => e
358
- STDERR.puts e
359
- STDERR.puts "Unable to tag repo at #{version}"
360
- exit 1
361
- end
355
+ sh "git tag -s -u #{@build.gpg_key} -m '#{version}' #{version}"
356
+ $?.success or fail "Unable to tag repo at #{version}"
362
357
  end
363
358
 
364
359
  def rand_string
@@ -428,7 +423,7 @@ end
428
423
 
429
424
  def hostname
430
425
  require 'socket'
431
- host = Socket.gethostname
426
+ Socket.gethostname
432
427
  end
433
428
 
434
429
  # Loop a block up to the number of attempts given, exiting when we receive success
@@ -446,9 +441,9 @@ def retry_on_fail(args, &blk)
446
441
  end
447
442
  end
448
443
  else
449
- raise "retry_on_fail requires and arg (:times => x) where x is an Integer/Fixnum, and a block to execute"
444
+ fail "retry_on_fail requires and arg (:times => x) where x is an Integer/Fixnum, and a block to execute"
450
445
  end
451
- raise "Block failed maximum of #{args[:times]} tries. Exiting.." unless success
446
+ fail "Block failed maximum of #{args[:times]} tries. Exiting.." unless success
452
447
  end
453
448
 
454
449
  def deprecate(old_cmd, new_cmd=nil)
@@ -497,9 +492,8 @@ def data_from_yaml(file)
497
492
  begin
498
493
  input_data = YAML.load_file(file) || {}
499
494
  rescue => e
500
- puts "There was an error loading data from #{file}."
501
- puts e.backtrace.join("\n")
502
- exit 1
495
+ STDERR.puts "There was an error loading data from #{file}."
496
+ fail e.backtrace.join("\n")
503
497
  end
504
498
  input_data
505
499
  end
@@ -517,11 +511,8 @@ end
517
511
  # This method takes two arguments
518
512
  # 1) String - the URL to post to
519
513
  # 2) Array - Ordered array of name=VALUE curl form parameters
520
- def curl_form_data(uri, form_data=[])
521
- unless curl = find_tool("curl")
522
- warn "Couldn't find curl. Curl is required for posting jenkins to trigger a build. Please install curl and try again."
523
- exit 1
524
- end
514
+ def curl_form_data(uri, form_data=[], options={})
515
+ curl = find_tool("curl") or fail "Couldn't find curl. Curl is required for posting jenkins to trigger a build. Please install curl and try again."
525
516
  #
526
517
  # Begin constructing the post string.
527
518
  # First, assemble the form_data arguments
@@ -531,10 +522,59 @@ def curl_form_data(uri, form_data=[])
531
522
  post_string << "#{param} "
532
523
  end
533
524
 
534
- # Add the uri and we're off
525
+ # Add the uri
535
526
  post_string << "#{uri}"
536
- sh "#{curl} #{post_string}"
527
+
528
+ # If this is quiet, we're going to silence all output
529
+ if options[:quiet]
530
+ post_string << " >/dev/null 2>&1"
531
+ end
532
+
533
+ %x{#{curl} #{post_string}}
537
534
  return $?.success?
538
535
  end
539
536
 
537
+ def random_string length
538
+ rand(36**length).to_s(36)
539
+ end
540
+
541
+ # Use the curl to create a jenkins job from a valid XML
542
+ # configuration file.
543
+ # Returns the URL to the job
544
+ def create_jenkins_job(name, xml_file)
545
+ create_url = "http://#{@build.jenkins_build_host}/createItem?name=#{name}"
546
+ form_args = ["-H", '"Content-Type: application/xml"', "--data-binary", "@#{xml_file}"]
547
+ curl_form_data(create_url, form_args)
548
+ "http://#{@build.jenkins_build_host}/job/#{name}"
549
+ end
540
550
 
551
+ # Use the curl to check of a named job is defined on the jenkins server. We
552
+ # curl the config file rather than just checking if the job exists by curling
553
+ # the job url and passing --head because jenkins will mistakenly return 200 OK
554
+ # if you issue multiple very fast requests just requesting the header.
555
+ def jenkins_job_exists?(name)
556
+ job_url = "http://#{@build.jenkins_build_host}/job/#{name}/config.xml"
557
+ form_args = ["--silent", "--fail"]
558
+ curl_form_data(job_url, form_args, :quiet => true)
559
+ end
560
+
561
+ def require_library_or_fail(library)
562
+ begin
563
+ require library
564
+ rescue LoadError
565
+ fail "Could not load #{library}. #{library} is required by the packaging repo for this task"
566
+ end
567
+ end
568
+
569
+ # Use the provided URL string to print important information with
570
+ # ASCII emphasis
571
+ def print_url_info(url_string)
572
+ puts "\n////////////////////////////////////////////////////////////////////////////////\n\n
573
+ Build submitted. To view your build progress, go to\n#{url_string}\n\n
574
+ ////////////////////////////////////////////////////////////////////////////////\n\n"
575
+ end
576
+
577
+ def escape_html(uri)
578
+ require 'cgi'
579
+ CGI.escapeHTML(uri)
580
+ end