Class: Hudson::CLI
- Includes:
- Formatting
- Defined in:
- lib/hudson/cli.rb,
lib/hudson/cli/formatting.rb
Defined Under Namespace
Modules: Formatting
Class Method Summary collapse
Instance Method Summary collapse
- #add_node(slave_host) ⇒ Object
- #build(project_path = ".") ⇒ Object
- #create(project_path) ⇒ Object
- #help(*args) ⇒ Object
- #list ⇒ Object
- #nodes ⇒ Object
- #remove(project_path) ⇒ Object
- #server ⇒ Object
- #version ⇒ Object
Methods included from Formatting
Class Method Details
.common_options ⇒ Object
13 14 15 16 |
# File 'lib/hudson/cli.rb', line 13 def self. method_option :host, :desc => 'connect to hudson server on this host' method_option :port, :desc => 'connect to hudson server on this port' end |
.help(shell) ⇒ Object
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 |
# File 'lib/hudson/cli.rb', line 183 def self.help(shell, *) list = printable_tasks shell.say <<-USEAGE Hudson.rb is a smart set of utilities for making continuous integration as simple as possible Usage: hudson command [arguments] [options] USEAGE shell.say "Commands:" shell.print_table(list, :ident => 2, :truncate => true) shell.say (shell) end |
Instance Method Details
#add_node(slave_host) ⇒ Object
164 165 166 167 168 169 170 171 |
# File 'lib/hudson/cli.rb', line 164 def add_node(slave_host) select_hudson_server() if Hudson::Api.add_node({:slave_host => slave_host}.merge()) shell.say "Added slave node #{slave_host}", :green else error "Failed to add slave node #{slave_host}" end end |
#build(project_path = ".") ⇒ Object
98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/hudson/cli.rb', line 98 def build(project_path = ".") select_hudson_server() FileUtils.chdir(project_path) do name = File.basename(FileUtils.pwd) if Hudson::Api.build_job(name) shell.say "Build for '#{name}' running now..." else error "No job '#{name}' on server." end end end |
#create(project_path) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/hudson/cli.rb', line 56 def create(project_path) select_hudson_server() FileUtils.chdir(project_path) do unless scm = Hudson::ProjectScm.discover error "Cannot determine project SCM. Currently supported: #{Hudson::ProjectScm.supported}" end unless File.exists?("Gemfile") error "Ruby/Rails projects without a Gemfile are currently unsupported." end begin template = [:template] job_config = Hudson::JobConfigBuilder.new(template) do |c| c.scm = scm.url c.assigned_node = [:"assigned-node"] if [:"assigned-node"] c.public_scm = [:"public-scm"] end name = File.basename(FileUtils.pwd) if Hudson::Api.create_job(name, job_config, ) build_url = "#{@uri}/job/#{name.gsub(/\s/,'%20')}/build" shell.say "Added #{template} project '#{name}' to Hudson.", :green unless [:"no-build"] shell.say "Triggering initial build..." Hudson::Api.build_job(name) shell.say "Trigger additional builds via:" else shell.say "Trigger builds via:" end shell.say " URL: "; shell.say "#{build_url}", :yellow shell.say " CLI: "; shell.say "#{cmd} build #{name}", :yellow else error "Failed to create project '#{name}'" end rescue Hudson::JobConfigBuilder::InvalidTemplate error "Invalid job template '#{template}'." rescue Hudson::Api::JobAlreadyExistsError error "Job '#{name}' already exists." end end end |
#help(*args) ⇒ Object
174 175 176 |
# File 'lib/hudson/cli.rb', line 174 def help(*args) super(*args) end |
#list ⇒ Object
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/hudson/cli.rb', line 126 def list select_hudson_server() summary = Hudson::Api.summary unless summary["jobs"].blank? shell.say "#{@uri}:", :bold summary["jobs"].each do |job| color = job['color'] bold = color =~ /anime/ color = 'red' if color == 'red_anime' color = 'green' if color == 'blue' || color == 'blue_anime' color = 'yellow' if color == 'grey' || color == 'disabled' shell.say "* "; shell.say(shell.set_color(job['name'], color.to_sym, bold), nil, true) end shell.say "" else shell.say "#{@uri}: "; shell.say "no jobs", :yellow end end |
#nodes ⇒ Object
147 148 149 150 151 152 153 154 |
# File 'lib/hudson/cli.rb', line 147 def nodes select_hudson_server() nodes = Hudson::Api.nodes nodes["computer"].each do |node| color = node["offline"] ? :red : :green shell.say node["displayName"], color end end |
#remove(project_path) ⇒ Object
112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/hudson/cli.rb', line 112 def remove(project_path) select_hudson_server() FileUtils.chdir(project_path) do name = File.basename(FileUtils.pwd) if Hudson::Api.delete_job(name) shell.say "Removed project '#{name}' from Hudson." else error "Failed to delete project '#{name}'." end end end |
#server ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/hudson/cli.rb', line 25 def server if [:kill] require 'socket' TCPSocket.open("localhost", [:control]) do |sock| sock.write("0") end exit end serverhome = File.join([:home]) javatmp = File.join(serverhome, "javatmp") FileUtils.mkdir_p serverhome FileUtils.mkdir_p javatmp FileUtils.cp_r Hudson::PLUGINS, serverhome ENV['HUDSON_HOME'] = serverhome cmd = ["java", "-Djava.io.tmpdir=#{javatmp}", "-jar", Hudson::WAR] cmd << "--daemon" if [:daemon] cmd << "--logfile=#{File.([:logfile])}" if [:logfile] cmd << "--httpPort=#{[:port]}" cmd << "--controlPort=#{[:control]}" shell.say cmd.join(" ") exec(*cmd) end |
#version ⇒ Object
179 180 181 |
# File 'lib/hudson/cli.rb', line 179 def version shell.say "#{Hudson::VERSION} (Hudson Server #{Hudson::HUDSON_VERSION})" end |