Module: Jenkins2::Client::PluginCommands

Included in:
Jenkins2::Client
Defined in:
lib/jenkins2/client/plugin_commands.rb

Instance Method Summary collapse

Instance Method Details

#install_plugins(*names) ⇒ Object

Installs plugins by short name (like thinBackup).

names

List of short names.



6
7
8
9
10
11
12
# File 'lib/jenkins2/client/plugin_commands.rb', line 6

def install_plugins( *names )
  api_request( :post, '/pluginManager/install' ) do |req|
    req.form_data = names.flatten.inject({}) do |memo,obj|
      memo.merge "plugin.#{obj}.default" => 'on'
    end.merge( 'dynamicLoad' => 'Install without restart' )
  end
end

#list_pluginsObject

Lists installed plugins



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

def list_plugins
  api_request( :get, '/pluginManager/api/json?depth=1' )['plugins']
end

#plugins_installed?(*names) ⇒ Boolean

Checks, if all of the plugins from the passed list are installed

names

List of short names of plugins (like thinBackup).

Returns:

  • (Boolean)


30
31
32
33
34
35
36
# File 'lib/jenkins2/client/plugin_commands.rb', line 30

def plugins_installed?( *names )
  plugins = list_plugins
  return false if plugins.nil?
  names.flatten.all? do |name|
    plugins.detect{|p| p['shortName'] == name and !p['deleted'] }
  end
end

#uninstall_plugin(name) ⇒ Object

Uninstalls a plugin

name

Plugin short name



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

def uninstall_plugin( name )
  api_request( :post, "/pluginManager/plugin/#{name}/doUninstall" ) do |req|
    req.form_data = { 'Submit' => 'Yes', 'json' => '{}' }
  end
end

#upload_plugin(plugin_file) ⇒ Object

Installs a plugin by uploading *.hpi or *.jpi file.

plugin_file

A *.hpi or *.jpi file itself ( not some path )



16
17
18
19
20
21
# File 'lib/jenkins2/client/plugin_commands.rb', line 16

def upload_plugin( plugin_file )
  api_request( :post, '/pluginManager/uploadPlugin' ) do |req|
    req.body = plugin_file
    req.content_type = 'multipart/form-data'
  end
end

#wait_plugins_installed(*names, max_wait_minutes: 2) ⇒ Object



46
47
48
49
50
# File 'lib/jenkins2/client/plugin_commands.rb', line 46

def wait_plugins_installed( *names, max_wait_minutes: 2 )
  Wait.wait( max_wait_minutes: max_wait_minutes ) do
    plugins_installed? names
  end
end