This repository has been archived by the owner on Mar 8, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a publisher to package up the generated box
Enabling this post-build step means the wrapper will not destroy the machine, but the publisher will take over responsibility for that instead. Related to #10
- Loading branch information
R. Tyler Croy
committed
Mar 16, 2012
1 parent
6e93b99
commit 52c5222
Showing
4 changed files
with
68 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
require 'rubygems' | ||
require 'vagrant' | ||
|
||
|
||
module Vagrant | ||
class PackagePublisher < Jenkins::Tasks::Publisher | ||
display_name "Package Vagrant box" | ||
|
||
attr_accessor :boxname | ||
def initialize(attrs) | ||
@vagrant = nil | ||
@boxname = attrs['boxname'] | ||
end | ||
|
||
def prebuild(build, listener) | ||
# To run packaging, we need to own the destroy of the box | ||
build.env[:vagrant_disable_destroy] = true | ||
end | ||
|
||
def perform(build, launcher, listener) | ||
@vagrant = build.env[:vagrant] | ||
if @vagrant.nil? | ||
built.halt "OH CRAP! I don't seem to have a Vagrant instance in the publisher" | ||
end | ||
|
||
unless build.env[:vagrant_dirty] | ||
listener.info("It doesn't appear any changes were made inside the Vagrant VM") | ||
listener.info("I'm going to save us all a lot of grief and skip packaging it up then") | ||
return | ||
end | ||
|
||
name = @boxname | ||
if name.nil? or name.empty? | ||
name = 'package.box' | ||
end | ||
unless name.end_with? '.box' | ||
name = "#{name}.box" | ||
end | ||
|
||
listener.info("Preparing to export the current Vagrant box to a file named: #{name}") | ||
output = File.expand_path(File.join(build.workspace.to_s, name)) | ||
@vagrant.cli('package', '--output', output) | ||
@vagrant.cli('destroy', '-f') | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<% | ||
f = taglib("/lib/form") | ||
f.block do | ||
f.entry(:title => 'Name of .box file (optional)', | ||
:field => 'boxname', | ||
:description => 'Name to give the .box file packaged by Vagrant') do | ||
f.textbox | ||
end | ||
end | ||
%> |