Class: Integrations::Jenkins

Inherits:
BaseCi show all
Extended by:
Gitlab::Utils::Override
Includes:
EnableSslVerification, HasWebHook
Defined in:
app/models/integrations/jenkins.rb

Constant Summary

Constants inherited from Integration

Integration::BASE_CLASSES, Integration::DEV_INTEGRATION_NAMES, Integration::INTEGRATION_NAMES, Integration::PROJECT_SPECIFIC_INTEGRATION_NAMES, Integration::SECTION_TYPE_CONNECTION, Integration::UnknownType

Constants inherited from ApplicationRecord

ApplicationRecord::MAX_PLUCK

Instance Attribute Summary

Attributes included from Importable

#imported, #importing

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Gitlab::Utils::Override

extended, extensions, included, method_added, override, prepended, queue_verification, verify!

Methods included from HasWebHook

#execute_web_hook!, #hook_ssl_verification, #update_web_hook!

Methods included from EnableSslVerification

#fields, #initialize_properties

Methods inherited from BaseCi

#build_page, #commit_status, #valid_token?

Methods inherited from Integration

#activate_disabled_reason, #activated?, #api_field_names, #async_execute, #attributes, available_integration_names, available_integration_types, boolean_accessor, build_from_integration, #category, #configurable_events, create_from_active_default_integrations, default_integration, default_test_event, #default_test_event, dev_integration_names, #dup, #editable?, #event_channel_names, event_description, #event_field, #event_names, event_names, field, #fields, fields, find_or_initialize_all_non_project_specific, find_or_initialize_non_project_specific_integration, #global_fields, #group_level?, #inheritable?, inherited_descendants_from_self_or_ancestors_from, #initialize_properties, instance_exists_for?, #instance_level?, integration_name_to_model, integration_name_to_type, integration_names, #json_fields, #operating?, #parent, #project_level?, project_specific_integration_names, prop_accessor, #properties=, #reencrypt_properties, #reset_updated_properties, #secret_fields, #sections, #show_active_box?, #supported_events, #supports_data_fields?, #testable?, #to_data_fields_hash, #to_integration_hash, #to_param, #updated_properties

Methods included from ResetSecretFields

#exposing_secrets_fields

Methods included from Loggable

#build_message, #log_error, #log_exception, #log_info, #logger

Methods inherited from ApplicationRecord

cached_column_list, #create_or_load_association, declarative_enum, default_select_columns, id_in, id_not_in, iid_in, pluck_primary_key, primary_key_in, #readable_by?, safe_ensure_unique, safe_find_or_create_by, safe_find_or_create_by!, #to_ability_name, underscore, where_exists, where_not_exists, with_fast_read_statement_timeout, without_order

Methods included from SensitiveSerializableHash

#serializable_hash

Class Method Details

.supported_eventsObject


72
73
74
# File 'app/models/integrations/jenkins.rb', line 72

def self.supported_events
  %w(push merge_request tag_push)
end

.to_paramObject


89
90
91
# File 'app/models/integrations/jenkins.rb', line 89

def self.to_param
  'jenkins'
end

Instance Method Details

#descriptionObject


80
81
82
# File 'app/models/integrations/jenkins.rb', line 80

def description
  s_('Run CI/CD pipelines with Jenkins.')
end

#execute(data) ⇒ Object


46
47
48
49
50
# File 'app/models/integrations/jenkins.rb', line 46

def execute(data)
  return unless supported_events.include?(data[:object_kind])

  execute_web_hook!(data, "#{data[:object_kind]}_hook")
end

#helpObject


84
85
86
87
# File 'app/models/integrations/jenkins.rb', line 84

def help
  docs_link = ActionController::Base.helpers.link_to _('Learn more.'), Rails.application.routes.url_helpers.help_page_url('integration/jenkins'), target: '_blank', rel: 'noopener noreferrer'
  s_('Run CI/CD pipelines with Jenkins when you push to a repository, or when a merge request is created, updated, or merged. %{docs_link}').html_safe % { docs_link: docs_link.html_safe }
end

#hook_urlObject


64
65
66
67
68
69
70
# File 'app/models/integrations/jenkins.rb', line 64

def hook_url
  url = URI.parse(jenkins_url)
  url.path = File.join(url.path || '/', "project/#{project_name}")
  url.user = ERB::Util.url_encode(username) unless username.blank?
  url.password = ERB::Util.url_encode(password) unless password.blank?
  url.to_s
end

#reset_passwordObject


39
40
41
42
43
44
# File 'app/models/integrations/jenkins.rb', line 39

def reset_password
  # don't reset the password if a new one is provided
  if (jenkins_url_changed? || username.blank?) && !password_touched?
    self.password = nil
  end
end

#test(data) ⇒ Object


52
53
54
55
56
57
58
59
60
61
# File 'app/models/integrations/jenkins.rb', line 52

def test(data)
  begin
    result = execute(data)
    return { success: false, result: result[:message] } if result[:http_status] != 200
  rescue StandardError => error
    return { success: false, result: error }
  end

  { success: true, result: result[:message] }
end

#titleObject


76
77
78
# File 'app/models/integrations/jenkins.rb', line 76

def title
  'Jenkins'
end