Class: Jenkins::CLI
- Includes:
- Formatting
- Defined in:
- lib/jenkins/cli.rb,
lib/jenkins/cli/formatting.rb
Defined Under Namespace
Modules: Formatting
Class Method Summary collapse
Instance Method Summary collapse
- #add_node(slave_host) ⇒ Object
- #auth_info ⇒ Object
- #build(project_path = ".") ⇒ Object
- #build_details(job_name, build_number) ⇒ Object
- #configure ⇒ Object
- #create(project_path) ⇒ Object
- #default_host ⇒ Object
- #help(*args) ⇒ Object
- #job(name) ⇒ 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 17 18 19 |
# File 'lib/jenkins/cli.rb', line 13 def self. method_option :host, :desc => 'connect to jenkins server on this host' method_option :port, :desc => 'connect to jenkins server on this port' method_option :ssl, :desc => 'connect to jenkins server with ssl', :type => :boolean, :default => false method_option :username, :desc => 'connect to jenkins server with username' method_option :password, :desc => 'connect to jenkins server with password' end |
.help(shell) ⇒ Object
252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 |
# File 'lib/jenkins/cli.rb', line 252 def self.help(shell, *) list = printable_tasks shell.say <<-USEAGE Jenkins.rb is a smart set of utilities for making continuous integration as simple as possible Usage: jenkins 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
209 210 211 212 213 214 215 216 |
# File 'lib/jenkins/cli.rb', line 209 def add_node(slave_host) select_jenkins_server() if results = Jenkins::Api.add_node({:slave_host => slave_host}.merge()) shell.say "Added slave node '#{results[:name]}' to #{results[:slave_host]}", :green else error "Failed to add slave node #{slave_host}" end end |
#auth_info ⇒ Object
235 236 237 238 239 240 |
# File 'lib/jenkins/cli.rb', line 235 def auth_info if auth = Jenkins::Config.config['basic_auth'] shell.say "username: #{auth["username"]}" shell.say "password: #{auth["password"]}" end end |
#build(project_path = ".") ⇒ Object
95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/jenkins/cli.rb', line 95 def build(project_path = ".") select_jenkins_server() FileUtils.chdir(project_path) do name = File.basename(FileUtils.pwd) if Jenkins::Api.build_job(name) shell.say "Build for '#{name}' running now..." else error "No job '#{name}' on server." end end end |
#build_details(job_name, build_number) ⇒ Object
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'lib/jenkins/cli.rb', line 150 def build_details(job_name, build_number) select_jenkins_server() if build_details = Jenkins::Api.build_details(job_name, build_number) if [:hash] require "ap" ap build_details.parsed_response elsif [:json] puts build_details.parsed_response.to_json elsif [:yaml] require "yaml" puts build_details.parsed_response.to_yaml else error "Select an output format: --json, --yaml, --hash" end else error "Cannot find project '#{job_name}'." end end |
#configure ⇒ Object
229 230 231 232 |
# File 'lib/jenkins/cli.rb', line 229 def configure Jenkins::Api.setup_base_url() Jenkins::Api.cache_configuration! end |
#create(project_path) ⇒ Object
50 51 52 53 54 55 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 |
# File 'lib/jenkins/cli.rb', line 50 def create(project_path) select_jenkins_server() FileUtils.chdir(project_path) do unless scm = Jenkins::ProjectScm.discover([:scm]) error "Cannot determine project SCM. Currently supported: #{Jenkins::ProjectScm.supported}" end unless ([:template] == "none" || [:template] == "erlang" || [:"no-template"]) || File.exists?("Gemfile") error "Ruby/Rails projects without a Gemfile are currently unsupported." end begin template = [:"no-template"] ? 'none' : [:template] job_config = Jenkins::JobConfigBuilder.new(template) do |c| c.rubies = [:rubies].split(/\s*,\s*/) if [:rubies] c.node_labels = [:"node-labels"].split(/\s*,\s*/) if [:"node-labels"] c.scm = scm.url c.scm_branches = [:"scm-branches"].split(/\s*,\s*/) c.assigned_node = [:"assigned-node"] if [:"assigned-node"] c.public_scm = [:"public-scm"] end name = File.basename(FileUtils.pwd) if Jenkins::Api.create_job(name, job_config, ) build_url = "#{@uri}/job/#{name.gsub(/\s/,'%20')}/build" shell.say "Added#{' ' + template unless template == 'none'} project '#{name}' to Jenkins.", :green unless [:"no-build"] shell.say "Triggering initial build..." Jenkins::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 Jenkins::JobConfigBuilder::InvalidTemplate error "Invalid job template '#{template}'." rescue Jenkins::Api::JobAlreadyExistsError error "Job '#{name}' already exists." end end end |
#default_host ⇒ Object
219 220 221 222 223 224 225 |
# File 'lib/jenkins/cli.rb', line 219 def default_host if select_jenkins_server({}) display Jenkins::Api.base_uri else display "No default host yet. Use '--host host --port port' on your first request." end end |
#help(*args) ⇒ Object
243 244 245 |
# File 'lib/jenkins/cli.rb', line 243 def help(*args) super(*args) end |
#job(name) ⇒ Object
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/jenkins/cli.rb', line 126 def job(name) select_jenkins_server() if job = Jenkins::Api.job(name) if [:hash] require "ap" ap job.parsed_response elsif [:json] puts job.parsed_response.to_json elsif [:yaml] require "yaml" puts job.parsed_response.to_yaml else error "Select an output format: --json, --xml, --yaml, --hash" end else error "Cannot find project '#{name}'." end end |
#list ⇒ Object
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 |
# File 'lib/jenkins/cli.rb', line 171 def list select_jenkins_server() summary = Jenkins::Api.summary unless summary["jobs"].blank? shell.say "#{@uri}:", :bold summary["jobs"].each do |job| bold = job['color'] =~ /anime/ color = 'red' if job['color'] =~ /red/ color = 'green' if job['color'] =~ /(blue|green)/ 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
191 192 193 194 195 196 197 198 |
# File 'lib/jenkins/cli.rb', line 191 def nodes select_jenkins_server() nodes = Jenkins::Api.nodes nodes["computer"].each do |node| color = node["offline"] ? :red : :green shell.say node["displayName"], color end end |
#remove(project_path) ⇒ Object
109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/jenkins/cli.rb', line 109 def remove(project_path) select_jenkins_server() FileUtils.chdir(project_path) do name = File.basename(FileUtils.pwd) if Jenkins::Api.delete_job(name) shell.say "Removed project '#{name}' from Jenkins." else error "Failed to delete project '#{name}'." end end end |