Class: Integrations::Jenkins

Inherits:
Integration show all
Includes:
Base::Ci, EnableSslVerification, HasWebHook
Defined in:
app/models/integrations/jenkins.rb

Constant Summary

Constants included from Base::Integration

Base::Integration::BASE_ATTRIBUTES, Base::Integration::BASE_CLASSES, Base::Integration::DEV_INTEGRATION_NAMES, Base::Integration::ENCRYPTED_PROPERTIES_MAX_SIZE, Base::Integration::INSTANCE_LEVEL_ONLY_INTEGRATION_NAMES, Base::Integration::INTEGRATION_NAMES, Base::Integration::PROJECT_AND_GROUP_LEVEL_ONLY_INTEGRATION_NAMES, Base::Integration::PROJECT_LEVEL_ONLY_INTEGRATION_NAMES, Base::Integration::SECTION_TYPE_CONFIGURATION, Base::Integration::SECTION_TYPE_CONNECTION, Base::Integration::SECTION_TYPE_TRIGGER, Base::Integration::SNOWPLOW_EVENT_ACTION, Base::Integration::SNOWPLOW_EVENT_LABEL, Base::Integration::UnknownType

Constants inherited from ApplicationRecord

ApplicationRecord::MAX_PLUCK

Constants included from HasCheckConstraints

HasCheckConstraints::NOT_NULL_CHECK_PATTERN

Constants included from ResetOnColumnErrors

ResetOnColumnErrors::MAX_RESET_PERIOD

Class Method Summary collapse

Instance Method Summary collapse

Methods included from HasWebHook

#execute_web_hook!, #hook_ssl_verification, #update_web_hook!

Methods included from Base::Ci

#build_page, #commit_status, #valid_token?

Methods included from EnableSslVerification

#fields, #initialize_properties

Methods included from Base::Integration

#activate!, #activate_disabled_reason, #activated?, #after_build_from_integration, #api_field_names, #async_execute, #attributes, #attribution_notice, #category, #chat?, #ci?, #configurable_events, #deactivate!, #default_test_event, #description, #dup, #editable?, #event_channel_names, #event_names, #fields, #form_fields, #group_level?, #help, #inheritable?, #initialize_properties, #instance_level?, #json_fields, #manual_activation?, #operating?, #organization_id_from_parent, #parent, #project_level?, #reencrypt_properties, #reset_updated_properties, #secret_fields, #sections, #supported_events, #supports_data_fields?, #testable?, #title, #to_database_hash, #to_param, #toggle!, #updated_properties, #validate_encrypted_properties_size_limit

Methods included from Gitlab::Utils::Override

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

Methods inherited from ApplicationRecord

===, cached_column_list, #create_or_load_association, current_transaction, declarative_enum, default_select_columns, delete_all_returning, #deleted_from_database?, id_in, id_not_in, iid_in, nullable_column?, 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 Organizations::Sharding

#sharding_organization

Methods included from ResetOnColumnErrors

#reset_on_union_error, #reset_on_unknown_attribute_error

Methods included from Gitlab::SensitiveSerializableHash

#serializable_hash

Class Method Details

.descriptionObject



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

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

.helpObject



81
82
83
84
85
86
# File 'app/models/integrations/jenkins.rb', line 81

def self.help
  build_help_page_url(
    'integration/jenkins.md',
    s_("Run CI/CD pipelines with Jenkins when you push to a repository, or when a merge request is created, updated, or merged.")
  )
end

.supported_eventsObject



69
70
71
# File 'app/models/integrations/jenkins.rb', line 69

def self.supported_events
  %w[push merge_request tag_push]
end

.titleObject



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

def self.title
  'Jenkins'
end

.to_paramObject



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

def self.to_param
  'jenkins'
end

Instance Method Details

#execute(data) ⇒ Object



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

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

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

#hook_urlObject



57
58
59
60
61
62
63
# File 'app/models/integrations/jenkins.rb', line 57

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

#test(data) ⇒ Object



45
46
47
48
49
50
51
52
53
54
# File 'app/models/integrations/jenkins.rb', line 45

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

  { success: true, result: result.message }
end

#url_variablesObject



65
66
67
# File 'app/models/integrations/jenkins.rb', line 65

def url_variables
  {}
end