Class: JenkinsLauncher::APIInterface
- Inherits:
-
Object
- Object
- JenkinsLauncher::APIInterface
- Defined in:
- lib/jenkins_launcher/api_interface.rb
Instance Method Summary collapse
- #build_job(name) ⇒ Object
- #create_job(params) ⇒ Object
- #delete_job(name) ⇒ Object
- #display_progressive_console_output(name, refresh_rate) ⇒ Object
- #get_job_status(name) ⇒ Object
-
#initialize(options) ⇒ APIInterface
constructor
A new instance of APIInterface.
- #job_building?(name) ⇒ Boolean
- #job_exists?(name) ⇒ Boolean
- #stop_job(name) ⇒ Object
- #use_node(job_name, node_name) ⇒ Object
Constructor Details
#initialize(options) ⇒ APIInterface
Returns a new instance of APIInterface.
29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/jenkins_launcher/api_interface.rb', line 29 def initialize() if [:username] && [:server_ip] && ([:password] || [:password_base64]) creds = elsif [:creds_file] creds = YAML.load_file(File.([:creds_file], __FILE__)) elsif File.exist?("#{ENV['HOME']}/.jenkins_api_client/login.yml") creds = YAML.load_file(File.("#{ENV['HOME']}/.jenkins_api_client/login.yml", __FILE__)) else puts "Credentials are not set. Please pass them as parameters or set them in the default credentials file" exit 1 end @client = JenkinsApi::Client.new(creds) end |
Instance Method Details
#build_job(name) ⇒ Object
47 48 49 |
# File 'lib/jenkins_launcher/api_interface.rb', line 47 def build_job(name) @client.job.build(name) unless @client.job.get_current_build_status(name) == 'running' end |
#create_job(params) ⇒ Object
43 44 45 |
# File 'lib/jenkins_launcher/api_interface.rb', line 43 def create_job(params) @client.job.create_freestyle(params) unless @client.job.exists?(params[:name]) end |
#delete_job(name) ⇒ Object
63 64 65 |
# File 'lib/jenkins_launcher/api_interface.rb', line 63 def delete_job(name) @client.job.delete(name) end |
#display_progressive_console_output(name, refresh_rate) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/jenkins_launcher/api_interface.rb', line 71 def display_progressive_console_output(name, refresh_rate) debug_changed = false if @client.debug == true @client.debug = false debug_changed = true end response = @client.job.get_console_output(name) puts response['output'] unless response['more'] while response['more'] size = response['size'] puts response['output'] unless response['output'].chomp.empty? sleep refresh_rate response = @client.job.get_console_output(name, 0, size) end # Print the last few lines puts response['output'] unless response['output'].chomp.empty? @client.toggle_debug if debug_changed end |
#get_job_status(name) ⇒ Object
67 68 69 |
# File 'lib/jenkins_launcher/api_interface.rb', line 67 def get_job_status(name) @client.job.get_current_build_status(name) end |
#job_building?(name) ⇒ Boolean
59 60 61 |
# File 'lib/jenkins_launcher/api_interface.rb', line 59 def job_building?(name) @client.job.get_current_build_status(name) == 'running' end |
#job_exists?(name) ⇒ Boolean
55 56 57 |
# File 'lib/jenkins_launcher/api_interface.rb', line 55 def job_exists?(name) @client.job.exists?(name) end |
#stop_job(name) ⇒ Object
51 52 53 |
# File 'lib/jenkins_launcher/api_interface.rb', line 51 def stop_job(name) @client.job.stop_build(name) end |
#use_node(job_name, node_name) ⇒ Object
91 92 93 94 95 96 97 |
# File 'lib/jenkins_launcher/api_interface.rb', line 91 def use_node(job_name, node_name) if @client.node.list.include?(node_name) @client.job.restrict_to_node(job_name, node_name) else puts "Node '#{node_name}' is not found on Jenkins server. Skipping...".yellow end end |