Class: Chef::Application::Jenkins

Inherits:
Chef::Application
  • Object
show all
Defined in:
lib/chef/application/jenkins.rb

Constant Summary collapse

NO_COMMAND_GIVEN =
"You need to pass sync|prop|save|load as the first argument\n"

Instance Method Summary collapse

Instance Method Details

#configure_chefObject



114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# File 'lib/chef/application/jenkins.rb', line 114

def configure_chef
  begin
    self.parse_options
  rescue OptionParser::InvalidOption => e
      puts "#{e}\n"
      puts self.opt_parser
      exit 0
  rescue OptionParser::MissingArgument => e
      puts "#{e}\n"
      puts self.opt_parser
      exit 0
  end

  if config[:help]
    puts self.opt_parser
    exit 0
  end

  begin
    case config[:config_file]
    when /^(http|https):\/\//
      Chef::REST.new("", nil, nil).fetch(config[:config_file]) { |f| apply_config(f.path) }
    else
	load_config_file
    end
  rescue Errno::ENOENT => error
    Chef::Log.warn("*****************************************")
    Chef::Log.warn("Did not find config file: #{config[:config_file]}, using command line options.")
    Chef::Log.warn("*****************************************")

    Chef::Config.merge!(config)
  rescue SocketError => error
    Chef::Application.fatal!("Error getting config file #{Chef::Config[:config_file]}", 2)
  rescue Chef::Exceptions::ConfigurationError => error
    Chef::Application.fatal!("Error processing config file #{Chef::Config[:config_file]} with error #{error.message}", 2)
  rescue Exception => error
    Chef::Application.fatal!("Unknown error processing config file #{Chef::Config[:config_file]} with error #{error.message}", 2)
  end
end

#run_applicationObject

Run knife



97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/chef/application/jenkins.rb', line 97

def run_application
  Mixlib::Log::Formatter.show_time = false
  jenkins = Chef::Jenkins.new
  if ARGV[0] == "sync"
    jenkins.sync
  elsif ARGV[0] == "prop"
    jenkins.prop(config[:env_from], config[:env_to])
  elsif ARGV[0] == "save"
    jenkins.save(config[:env], config[:backup])
  elsif ARGV[0] == "load"
    jenkins.load(config[:env], config[:backup])
  else
    Chef::Application.fatal!("You must provide sync or prop as the first argument")
  end
  exit 0
end

#setup_applicationObject



154
155
# File 'lib/chef/application/jenkins.rb', line 154

def setup_application
end