Class: Jenkins2::Client

Inherits:
Object
  • Object
show all
Includes:
CredentialCommands, NodeCommands, PluginCommands
Defined in:
lib/jenkins2/client.rb,
lib/jenkins2/client/node_commands.rb,
lib/jenkins2/client/plugin_commands.rb,
lib/jenkins2/client/credential_commands.rb

Overview

The entrance point for your Jenkins remote management.

Defined Under Namespace

Modules: CredentialCommands, NodeCommands, PluginCommands

Constant Summary

Constants included from CredentialCommands

CredentialCommands::BOUNDARY

Instance Method Summary collapse

Methods included from NodeCommands

#connect_node, #create_node, #delete_node, #disconnect_node, #get_node, #get_node_xml, #node_connected?, #node_idle?, #node_online?, #offline_node, #online_node, #update_node, #wait_node_idle

Methods included from PluginCommands

#install_plugins, #list_plugins, #plugins_installed?, #uninstall_plugin, #upload_plugin, #wait_plugins_installed

Methods included from CredentialCommands

#create_credential, #create_credential_secret_file, #create_credential_secret_text, #create_credential_ssh, #create_credential_username_password, #delete_credential, #get_credential, #list_credentials

Constructor Details

#initialize(**args) ⇒ Client

Creates a “connection” to Jenkins. Keyword parameters:

server

Jenkins Server URL.

user

Jenkins API user. Can be omitted, if no authentication required.

key

Jenkins API key. Can be omitted, if no authentication required.



22
23
24
25
26
# File 'lib/jenkins2/client.rb', line 22

def initialize( **args )
	@server = args[:server]
	@user = args[:user]
	@key = args[:key]
end

Instance Method Details

#build(**args) ⇒ Object

Starts a build

job_name

Name of the job to build

build_params

Build parameters as hash, where keys are names of variables.



59
60
61
62
63
64
65
66
67
68
# File 'lib/jenkins2/client.rb', line 59

def build( **args )
	job, params = args[:job], args[:params]
	if params.nil? or params.empty?
		api_request( :post, "/job/#{job}/build" )
	else
		api_request( :post, "/job/#{job}/buildWithParameters" ) do |req|
			req.form_data = params
		end
	end
end

#cancel_shutdown(**args) ⇒ Object

Cancels the effect of prepare-for-shutdown command. Parameters are ignored



41
42
43
# File 'lib/jenkins2/client.rb', line 41

def cancel_shutdown( **args )
	api_request( :post, '/cancelQuietDown' )
end

#prepare_for_shutdown(**args) ⇒ Object

Stops executing new builds, so that the system can be eventually shut down safely. Parameters are ignored



35
36
37
# File 'lib/jenkins2/client.rb', line 35

def prepare_for_shutdown( **args )
	api_request( :post, '/quietDown' )
end

#versionObject

Returns Jenkins version



29
30
31
# File 'lib/jenkins2/client.rb', line 29

def version
	api_request( :get, '/', :raw )['X-Jenkins']
end

#wait_nodes_idle(max_wait_minutes: 60) ⇒ Object

Waits for all the nodes to become idle or until max_wait_minutes pass. Is expected to be called after prepare_for_shutdown, otherwise new builds will still be run.

max_wait_minutes

Maximum wait time in minutes. Default 60.



48
49
50
51
52
# File 'lib/jenkins2/client.rb', line 48

def wait_nodes_idle( max_wait_minutes: 60 )
	Wait.wait( max_wait_minutes: max_wait_minutes ) do
		api_request( :get, '/computer/api/json' )['busyExecutors'].zero?
	end
end