Class: JenkinsPipelineBuilder::View

Inherits:
Object
  • Object
show all
Defined in:
lib/jenkins_pipeline_builder/view.rb

Instance Method Summary collapse

Constructor Details

#initialize(generator) ⇒ View

Initializes a new View object.

Parameters:

  • generator (Generator)

    the client object



31
32
33
34
35
# File 'lib/jenkins_pipeline_builder/view.rb', line 31

def initialize(generator)
  @generator = generator
  @client = generator.client
  @logger = @client.logger
end

Instance Method Details

#create(params) ⇒ Object

Creates a listview by accepting the given parameters hash

Parameters:

  • params (Hash)

    options to create the new view

Options Hash (params):

  • :name (String)

    Name of the view

  • :type (String)

    Description of the view

  • :description (String)

    Description of the view

  • :status_filter (String)

    Filter jobs based on the status. Valid options: all_selected_jobs, enabled_jobs_only, disabled_jobs_only. Default: all_selected_jobs

  • :filter_queue (Boolean)

    true or false

  • :filter_executors (Boolean)

    true or false

  • :regex (String)

    Regular expression to filter jobs that are to be added to the view

Raises:

  • (ArgumentError)

    if the required parameter :name is not specified



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/jenkins_pipeline_builder/view.rb', line 67

def create(params)
  # Name is a required parameter. Raise an error if not specified
  raise ArgumentError, 'Name is required for creating view' unless params.is_a?(Hash) && params[:name]

  clean_up_views(params) unless JenkinsPipelineBuilder.debug
  params[:type] ||= 'listview'
  create_base_view(params[:name], params[:type], params[:parent_view])
  @logger.debug "Creating a #{params[:type]} view with params: #{params.inspect}"

  return if JenkinsPipelineBuilder.debug

  view_path = params[:parent_view].nil? ? '' : "/view/#{params[:parent_view]}"
  view_path += "/view/#{params[:name]}/configSubmit"

  @client.api_post_request(view_path, post_params(params))
end

#generate(path) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/jenkins_pipeline_builder/view.rb', line 37

def generate(path)
  hash = if path.end_with? 'json'
           JSON.parse(IO.read(path))
         else
           YAML.load_file(path)
         end

  hash.each do |item|
    Utils.symbolize_keys_deep!(item)
    create(item[:view]) if item[:view]
  end
end