Class: Readiness::GitLab::Pipelines

Inherits:
Client
  • Object
show all
Defined in:
lib/support_readiness/gitlab/pipelines.rb

Overview

TODO:

Get a pipeline’s test report

TODO:

Get a pipeline’s test report summary

TODO:

Create a new pipeline

TODO:

Retry jobs in a pipeline

TODO:

Cancel a pipeline’s jobs

TODO:

Delete a pipeline

TODO:

Update pipeline metadata

Defines the class Pipelines within the module Readiness::GitLab.

Author:

  • Jason Colyer

Since:

  • 1.0.13

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Client

auth_error, bad_request_error, convert_actions, convert_conditions, convert_standard_names_to_ids, convert_ticket_form_agent_conditions, convert_ticket_form_brands, convert_ticket_form_end_user_conditions, convert_ticket_form_names_to_ids, convert_view_names_to_ids, convert_view_restrictions, covert_ticket_form_field_ids, create_package!, erb_renderer, handle_request_error, not_found_error, not_processible_error, put_into_archive, recursively_deflate_directory, timestamp_filename, to_clean_json, to_clean_json_with_key, to_hash, to_nearly_clean_json, to_nearly_clean_json_with_key, to_param_string, write_entries

Constructor Details

#initialize(object = {}) ⇒ Pipelines

Creates a new Readiness::GitLab::Pipelines instance

Examples:

require 'support_readiness'
Readiness::GitLab::Pipelines.new

Parameters:

Author:

  • Jason Colyer

Since:

  • 1.0.13



31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/support_readiness/gitlab/pipelines.rb', line 31

def initialize(object = {})
  @created_at = object['created_at']
  @id = object['id']
  @iid = object['iid']
  @name = object['name']
  @project_id = object['project_id']
  @ref = object['ref']
  @sha = object['sha']
  @source = object['source']
  @status = object['status']
  @updated_at = object['updated_at']
  @web_url = object['web_url']
end

Instance Attribute Details

#created_atObject

Since:

  • 1.0.13



20
21
22
# File 'lib/support_readiness/gitlab/pipelines.rb', line 20

def created_at
  @created_at
end

#idObject

Since:

  • 1.0.13



20
21
22
# File 'lib/support_readiness/gitlab/pipelines.rb', line 20

def id
  @id
end

#iidObject

Since:

  • 1.0.13



20
21
22
# File 'lib/support_readiness/gitlab/pipelines.rb', line 20

def iid
  @iid
end

#nameObject

Since:

  • 1.0.13



20
21
22
# File 'lib/support_readiness/gitlab/pipelines.rb', line 20

def name
  @name
end

#project_idObject

Since:

  • 1.0.13



20
21
22
# File 'lib/support_readiness/gitlab/pipelines.rb', line 20

def project_id
  @project_id
end

#refObject

Since:

  • 1.0.13



20
21
22
# File 'lib/support_readiness/gitlab/pipelines.rb', line 20

def ref
  @ref
end

#shaObject

Since:

  • 1.0.13



20
21
22
# File 'lib/support_readiness/gitlab/pipelines.rb', line 20

def sha
  @sha
end

#sourceObject

Since:

  • 1.0.13



20
21
22
# File 'lib/support_readiness/gitlab/pipelines.rb', line 20

def source
  @source
end

#statusObject

Since:

  • 1.0.13



20
21
22
# File 'lib/support_readiness/gitlab/pipelines.rb', line 20

def status
  @status
end

#updated_atObject

Since:

  • 1.0.13



20
21
22
# File 'lib/support_readiness/gitlab/pipelines.rb', line 20

def updated_at
  @updated_at
end

#web_urlObject

Since:

  • 1.0.13



20
21
22
# File 'lib/support_readiness/gitlab/pipelines.rb', line 20

def web_url
  @web_url
end

Class Method Details

.find(client, project, pid) ⇒ Hash

Locates a project pipeline within GitLab. This will not exit on error (except Authentication errors)

Examples:

require 'support_readiness'
config = Readiness::GitLab::Configuration.new
config.token = 'test123abc'
client = Readiness::GitLab::Client.new(config)
project = Readiness::GitLab::Projects.find!(client, 1083469)
pipeline = Readiness::GitLab::Pipelines.find(client, project, 5)
puts pipeline.web_url
# => "https://gitlab.com/gitlab-com/support/support-team-meta/-/pipelines/5"

Parameters:

Returns:

  • (Hash)

See Also:

Author:

  • Jason Colyer

Since:

  • 1.0.13



101
102
103
104
105
106
107
# File 'lib/support_readiness/gitlab/pipelines.rb', line 101

def self.find(client, project, pid)
  response = client.connection.get "projects/#{project.id}/pipelines/#{pid}"
  handle_request_error(0, 'GitLab', response.status,  { action: 'get', id: pid }) unless response.status == 200
  return Pipelines.new(Oj.load(response.body)) if response.status == 200

  Oj.load(response.body)
end

.find!(client, project, pid) ⇒ Object

Locates a project pipeline within GitLab. This will exit on error

Examples:

require 'support_readiness'
config = Readiness::GitLab::Configuration.new
config.token = 'test123abc'
client = Readiness::GitLab::Client.new(config)
project = Readiness::GitLab::Projects.find!(client, 1083469)
pipeline = Readiness::GitLab::Pipelines.find!(client, project, 5)
puts pipeline.web_url
# => "https://gitlab.com/gitlab-com/support/support-team-meta/-/pipelines/5"

Parameters:

Returns:

See Also:

Author:

  • Jason Colyer

Since:

  • 1.0.13



128
129
130
131
132
# File 'lib/support_readiness/gitlab/pipelines.rb', line 128

def self.find!(client, project, pid)
  response = client.connection.get "projects/#{project.id}/pipelines/#{pid}"
  handle_request_error(1, 'GitLab', response.status, { action: 'Find pipeline', id: pid }) unless response.status == 200
  Pipelines.new(Oj.load(response.body))
end

.jobs(client, pipeline, limit = 0, filters = []) ⇒ Array

Lists all pipeline jobs. This is a wrapper of Jobs.list_pipeline

Examples:

require 'support_readiness'
config = Readiness::GitLab::Configuration.new
config.token = 'test123abc'
client = Readiness::GitLab::Client.new(config)
project = Readiness::GitLab::Projects.find!(client, 1083469)
pipeline = Readiness::GitLab::Pipelines.find!(client, project, 2)
jobs = Readiness::GitLab::Pipelines.jobs(client, pipeline, 2)
puts jobs.count
# => 187

Parameters:

  • client (Object)

    An instance of Client

  • pipeline (Object)

    An instance of Readiness::GitLab::Pieplines

  • limit (Integer) (defaults to: 0)

    The number of pages to stop at. Using 0 means to list all.

  • filters (Array) (defaults to: [])

    An array of filter Strings to use. Should be in the format of key=value

Returns:

  • (Array)

See Also:

Author:

  • Jason Colyer

Since:

  • 1.0.13



186
187
188
# File 'lib/support_readiness/gitlab/pipelines.rb', line 186

def self.jobs(client, pipeline, limit = 0, filters = [])
  Jobs.list_pipeline(client, pipeline, limit, filters)
end

.list(client, project, limit = 0, filters = []) ⇒ Array

Lists all pipelines for an object. Does not stop until it ends or the page limit is hit. This method can take a long time to run depending on the parameters used.

Examples:

require 'support_readiness'
config = Readiness::GitLab::Configuration.new
config.token = 'test123abc'
client = Readiness::GitLab::Client.new(config)
project = Readiness::GitLab::Projects.find!(client, 1083469)
pipelines = Readiness::GitLab::Pipelines.list(client, project, 2, ["name=Check System", "status=failed"])
puts pipelines.first.web_url
# => "https://gitlab.com/gitlab-com/support/support-team-meta/-/pipelines/2"

Parameters:

  • client (Object)

    An instance of Client

  • project (Object)
  • limit (Integer) (defaults to: 0)

    The number of pages to stop at. Using 0 means to list all.

  • filters (Array) (defaults to: [])

    An array of filter Strings to use. Should be in the format of key=value

Returns:

  • (Array)

See Also:

Author:

  • Jason Colyer

Since:

  • 1.0.13



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/support_readiness/gitlab/pipelines.rb', line 66

def self.list(client, project, limit = 0, filters = [])
  array = []
  page = 1
  loop do
    response = client.connection.get "projects/#{project.id}/pipelines?per_page=100&page=#{page}&#{to_param_string(filters)}"
    handle_request_error(0, 'GitLab', response.status) unless response.status == 200
    body = Oj.load(response.body)
    array += body.map { |p| Pipelines.new(p) }
    break if body.count < 100
    break if limit != 0 && array.count >= (limit * 100)

    page += 1
  end
  array
end

.variables(client, pipeline) ⇒ Hash

Gets the variables for a pipeline.

Examples:

require 'support_readiness'
config = Readiness::GitLab::Configuration.new
config.token = 'test123abc'
client = Readiness::GitLab::Client.new(config)
project = Readiness::GitLab::Projects.find!(client, 1083469)
pipeline = Readiness::GitLab::Pipelines.find!(client, project, 5)
variables = Readiness::GitLab::Pipelines.find!(client, pipeline)
pp variables
# => [
  {
    "key": "NAME",
    "variable_type": "env_var",
    "value": "Jason"
  }
]

Parameters:

Returns:

  • (Hash)

See Also:

Author:

  • Jason Colyer

Since:

  • 1.0.13



159
160
161
162
163
# File 'lib/support_readiness/gitlab/pipelines.rb', line 159

def self.variables(client, pipeline)
  response = client.connection.get "projects/#{pipeline.project_id}/pipleines/#{pipeline.iid}/variables"
  handle_request_error(0, 'GitLab', response.status,  { action: 'get', id: pid }) unless response.status == 200
  Oj.load(response.body)
end