Class: Jenkins2::CLI::CreateRole

Inherits:
Jenkins2::CLI show all
Defined in:
lib/jenkins2/cli/role_strategy.rb

Overview

Provides create-role command in CLI. Requires role-strategy plugin enabled.

Instance Attribute Summary

Attributes inherited from Jenkins2::CLI

#errors, #options

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Jenkins2::CLI

#call, class_to_command, #initialize, #parse, subcommands

Constructor Details

This class inherits a constructor from Jenkins2::CLI

Class Method Details

.descriptionObject



20
21
22
# File 'lib/jenkins2/cli/role_strategy.rb', line 20

def self.description
	'Create a role in role-strategy plugin.'
end

Instance Method Details

#add_optionsObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/jenkins2/cli/role_strategy.rb', line 24

def add_options
	parser.separator 'Mandatory arguments:'
	parser.on '--role ROLE', 'Role name.' do |r|
		options[:role] = r
	end
	parser.on '--type TYPE', 'Role type. One of: globalRoles, projectRoles, slaveRoles.' do |t|
		options[:type] = t
	end
	parser.separator 'Optional arguments:'
	parser.on '--permissions X,Y,..', Array, 'Comma-separated list of permissions.' do |p|
		options[:permissions] = p
	end
	parser.on '--pattern PATTERN', 'Slave or project pattern. Ignored for global roles.' do |p|
		options[:pattern] = p
	end
end

#mandatory_argumentsObject



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

def mandatory_arguments
	super + %i[role type]
end

#runObject



45
46
47
48
# File 'lib/jenkins2/cli/role_strategy.rb', line 45

def run
	jc.roles.create(role: options[:role], type: options[:type],
		permissions: options[:permissions], pattern: options[:pattern])
end