Sha256: 45ef039928f3894158b774757e33c89604b9d763d7d79d8ade73be960c389a79

Contents?: true

Size: 885 Bytes

Versions: 1

Compression:

Stored size: 885 Bytes

Contents

require 'net/ssh'

class JobsController < MVCLI::Controller
  requires :compute
  requires :command
  requires :job

  def create
    template = Jobs::CreateForm
    argv = MVCLI::Argv.new command.argv
    form = template.new argv.options
    command.output.puts "Setting up new jenkins job: #{form.job_name} on server: #{server.name}."
    sleep(1)
    xml = job.job_template(form.job_repo, form.job_command)
    Net::SSH.start("#{server.ipv4_address}", "root") do |ssh|
      # 'ssh' is an instance of Net::SSH::Connection::Session
      ssh.exec! "echo '#{xml}' >> #{form.job_name}-config.xml"
      ssh.exec! "java -jar /home/jenkins/jenkins-cli.jar -s http://0.0.0.0:8080 create-job #{form.job_name} < #{form.job_name}-config.xml"
    end
    return server
  end

  private

  def server
    compute.servers.find {|s| s.name == params[:id]} or fail Fog::Errors::NotFound
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rumm-0.1.0 app/controllers/jobs_controller.rb