Class: MSDeploy

Inherits:
Object
  • Object
show all
Includes:
Albacore::RunCommand, Albacore::Task
Defined in:
lib/albacore/msdeploy.rb

Instance Attribute Summary collapse

Attributes included from Albacore::RunCommand

#command, #working_directory

Attributes included from Logging

#current_log_device, #logger

Instance Method Summary collapse

Methods included from Albacore::RunCommand

#get_command, #run_command

Methods included from AttrMethods

#attr_array, #attr_hash

Methods included from Albacore::Task

clean_dirname, create_rake_task, include_config, included

Methods included from UpdateAttributes

#<<, #update_attributes

Methods included from YAMLConfig

#configure, #load_config_by_task_name

Methods included from Logging

#create_logger, #log_device=, #log_level, #log_level=

Methods included from Failure

#fail_with_message

Constructor Details

#initializeMSDeploy

Returns a new instance of MSDeploy.



13
14
15
16
17
18
# File 'lib/albacore/msdeploy.rb', line 13

def initialize
  @deploy_package = Dir.pwd
  @noop = false
  super()
  update_attributes Albacore.configuration.msdeploy.to_hash
end

Instance Attribute Details

#additional_parametersObject

Returns the value of attribute additional_parameters.



11
12
13
# File 'lib/albacore/msdeploy.rb', line 11

def additional_parameters
  @additional_parameters
end

#deploy_packageObject

Returns the value of attribute deploy_package.



11
12
13
# File 'lib/albacore/msdeploy.rb', line 11

def deploy_package
  @deploy_package
end

#noopObject

Returns the value of attribute noop.



11
12
13
# File 'lib/albacore/msdeploy.rb', line 11

def noop
  @noop
end

#parameters_fileObject

Returns the value of attribute parameters_file.



11
12
13
# File 'lib/albacore/msdeploy.rb', line 11

def parameters_file
  @parameters_file
end

#passwordObject

Returns the value of attribute password.



11
12
13
# File 'lib/albacore/msdeploy.rb', line 11

def password
  @password
end

#serverObject

Returns the value of attribute server.



11
12
13
# File 'lib/albacore/msdeploy.rb', line 11

def server
  @server
end

#usernameObject

Returns the value of attribute username.



11
12
13
# File 'lib/albacore/msdeploy.rb', line 11

def username
  @username
end

Instance Method Details

#executeObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/albacore/msdeploy.rb', line 20

def execute
  if(@command.nil?)
    @command = get_msdeploy_path
  end

  cmd_params = []
  cmd_params << get_package
  cmd_params << get_destination
  cmd_params << get_parameters
  cmd_params << get_constant_parameters
  
  if(!@additional_parameters.nil?)
    cmd_params << @additional_parameters
  end
  cmd_params << get_whatif

  result = run_command "MSDeploy Command", "#{cmd_params.join(" ")}"

  failure_msg = 'MSDeploy Failed.  See build log for details'
  fail_with_message failure_msg if !result
end

#get_constant_parametersObject



119
120
121
# File 'lib/albacore/msdeploy.rb', line 119

def get_constant_parameters
  return "-verb:sync  -disableLink:AppPoolExtension  -disableLink:ContentExtension  -disableLink:CertificateExtension "
end

#get_destinationObject



84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/albacore/msdeploy.rb', line 84

def get_destination
  if(@server.nil?)
    #no server so use auto
    return "-dest:auto,includeAcls='False'"
  end
  destination_string = "-dest:auto,computerName='#{@server}'"
  if(!@username.nil?)
    destination_string  << ",userName='#{@username}'"
  end
  if(!@password.nil?)
     destination_string  << ",password='#{@password}'"
   end
   return destination_string << ",includeAcls='False'"
end

#get_msdeploy_pathObject



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/albacore/msdeploy.rb', line 42

def get_msdeploy_path
  #check the environment paths
  ENV['PATH'].split(';').each do |path|
    msdeploy_path = File.join(path, 'msdeploy.exe')
    return msdeploy_path if File.exists?(msdeploy_path)
  end

  #check the environment variables
  if ENV['MSDeployPath']
    msdeploy_path = File.join(ENV['MSDeployPath'], 'msdeploy.exe')
    return msdeploy_path if File.exists?(msdeploy_path)
  end

  #check if it's in registry
  Win32::Registry::HKEY_LOCAL_MACHINE.open('SOFTWARE\Microsoft\IIS Extensions\MSDeploy\2') do |reg|
    reg_typ, reg_val = reg.read('InstallPath') # no checking for x86 here.
    msdeploy_path = reg_val
    return msdeploy_path if File.exists?(msdeploy_path)
  end

  fail_with_message 'MSDeploy could not be found is it installed?'
end

#get_packageObject



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/albacore/msdeploy.rb', line 65

def get_package
  #is it a direct file
  if(File.file?(@deploy_package))
    return "-source:package='#{File.expand_path(@deploy_package)}'"
  end
  
  #try directory with zip in it
  Dir.glob("#{@deploy_package}/**.zip") do |zip|
    puts File.expand_path(zip)
    return "-source:package='#{File.expand_path(zip)}'"
  end
  # must be an archive directory
  package_location = "#{@deploy_package}/archive"
  if(File.exists?(package_location))
    return "-source:archiveDir='#{File.expand_path(package_location)}'"
  end
  fail_with_message "Could not find the MSDeploy package to deploy."
end

#get_parametersObject



99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/albacore/msdeploy.rb', line 99

def get_parameters
 if (!@parameters_file.nil?)
    Dir.glob("#{@parameters_file}") do |parameters| 
      return "-setParamFile:\"#{File.expand_path(parameters)}\""
    end 
    fail_with_message 'Could not find parameter file specified.'
  else
    Dir.glob("#{@deploy_package}/**.SetParameters.xml") do |parameters| 
      return "-setParamFile:\"#{File.expand_path(parameters)}\""
    end
  end
  return nil  
end

#get_whatifObject



113
114
115
116
117
# File 'lib/albacore/msdeploy.rb', line 113

def get_whatif
  if(@noop)
    return "-whatif"
  end
end