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.



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

def initialize( **args )
	@server = args[:server]
	@user = args[:user]
	@key = args[:key]
	@crumb = nil
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.



67
68
69
70
71
72
73
74
75
76
# File 'lib/jenkins2/client.rb', line 67

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



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

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



37
38
39
# File 'lib/jenkins2/client.rb', line 37

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

#restart!(**args) ⇒ Object

Forcefully restart Jenkins NOW! Parameters are ignored



43
44
45
# File 'lib/jenkins2/client.rb', line 43

def restart!( **args )
	api_request( :post, '/restart' )
end

#versionObject

Returns Jenkins version



31
32
33
# File 'lib/jenkins2/client.rb', line 31

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.



56
57
58
59
60
# File 'lib/jenkins2/client.rb', line 56

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