Class: Readiness::GitLab::Jobs

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

Overview

TODO:

List pipeline trigger jobs

TODO:

Get job token’s job

TODO:

Get GitLab agent by CI_JOB_TOKEN

TODO:

Get a log file

TODO:

Cancel a job

TODO:

Retry a job

TODO:

Erase a job

TODO:

Run a job

Defines the class Jobs 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 = {}) ⇒ Jobs

Creates a new Readiness::GitLab::Jobs instance

Examples:

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

Parameters:

Author:

  • Jason Colyer

Since:

  • 1.0.13



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/support_readiness/gitlab/jobs.rb', line 32

def initialize(object = {})
  @allow_failure = object['allow_failure']
  @archived = object['archived']
  @artifacts = object['artifacts']
  @artifacts_expire_at = object['artifacts_expire_at']
  @commit = object['commit']
  @coverage = object['coverage']
  @created_at = object['created_at']
  @duration = object['duration']
  @erased_at = object['erased_at']
  @failure_reason = object['failure_reason']
  @finished_at = object['finished_at']
  @id = object['id']
  @name = object['name']
  @pipeline = object['pipeline']
  @project = object['project']
  @queued_duration = object['queued_duration']
  @ref = object['ref']
  @runner = object['runner']
  @runner_manager = object['runner_manager']
  @stage = object['stage']
  @started_at = object['started_at']
  @status = object['status']
  @tag = object['tag']
  @tag_list = object['tag_list']
  @user = object['user']
  @web_url = object['web_url']
end

Instance Attribute Details

#allow_failureObject

Since:

  • 1.0.13



21
22
23
# File 'lib/support_readiness/gitlab/jobs.rb', line 21

def allow_failure
  @allow_failure
end

#archivedObject

Since:

  • 1.0.13



21
22
23
# File 'lib/support_readiness/gitlab/jobs.rb', line 21

def archived
  @archived
end

#artifactsObject

Since:

  • 1.0.13



21
22
23
# File 'lib/support_readiness/gitlab/jobs.rb', line 21

def artifacts
  @artifacts
end

#artifacts_expire_atObject

Since:

  • 1.0.13



21
22
23
# File 'lib/support_readiness/gitlab/jobs.rb', line 21

def artifacts_expire_at
  @artifacts_expire_at
end

#commitObject

Since:

  • 1.0.13



21
22
23
# File 'lib/support_readiness/gitlab/jobs.rb', line 21

def commit
  @commit
end

#coverageObject

Since:

  • 1.0.13



21
22
23
# File 'lib/support_readiness/gitlab/jobs.rb', line 21

def coverage
  @coverage
end

#created_atObject

Since:

  • 1.0.13



21
22
23
# File 'lib/support_readiness/gitlab/jobs.rb', line 21

def created_at
  @created_at
end

#durationObject

Since:

  • 1.0.13



21
22
23
# File 'lib/support_readiness/gitlab/jobs.rb', line 21

def duration
  @duration
end

#erased_atObject

Since:

  • 1.0.13



21
22
23
# File 'lib/support_readiness/gitlab/jobs.rb', line 21

def erased_at
  @erased_at
end

#failure_reasonObject

Since:

  • 1.0.13



21
22
23
# File 'lib/support_readiness/gitlab/jobs.rb', line 21

def failure_reason
  @failure_reason
end

#finished_atObject

Since:

  • 1.0.13



21
22
23
# File 'lib/support_readiness/gitlab/jobs.rb', line 21

def finished_at
  @finished_at
end

#idObject

Since:

  • 1.0.13



21
22
23
# File 'lib/support_readiness/gitlab/jobs.rb', line 21

def id
  @id
end

#nameObject

Since:

  • 1.0.13



21
22
23
# File 'lib/support_readiness/gitlab/jobs.rb', line 21

def name
  @name
end

#pipelineObject

Since:

  • 1.0.13



21
22
23
# File 'lib/support_readiness/gitlab/jobs.rb', line 21

def pipeline
  @pipeline
end

#projectObject

Since:

  • 1.0.13



21
22
23
# File 'lib/support_readiness/gitlab/jobs.rb', line 21

def project
  @project
end

#queued_durationObject

Since:

  • 1.0.13



21
22
23
# File 'lib/support_readiness/gitlab/jobs.rb', line 21

def queued_duration
  @queued_duration
end

#refObject

Since:

  • 1.0.13



21
22
23
# File 'lib/support_readiness/gitlab/jobs.rb', line 21

def ref
  @ref
end

#runnerObject

Since:

  • 1.0.13



21
22
23
# File 'lib/support_readiness/gitlab/jobs.rb', line 21

def runner
  @runner
end

#runner_managerObject

Since:

  • 1.0.13



21
22
23
# File 'lib/support_readiness/gitlab/jobs.rb', line 21

def runner_manager
  @runner_manager
end

#stageObject

Since:

  • 1.0.13



21
22
23
# File 'lib/support_readiness/gitlab/jobs.rb', line 21

def stage
  @stage
end

#started_atObject

Since:

  • 1.0.13



21
22
23
# File 'lib/support_readiness/gitlab/jobs.rb', line 21

def started_at
  @started_at
end

#statusObject

Since:

  • 1.0.13



21
22
23
# File 'lib/support_readiness/gitlab/jobs.rb', line 21

def status
  @status
end

#tagObject

Since:

  • 1.0.13



21
22
23
# File 'lib/support_readiness/gitlab/jobs.rb', line 21

def tag
  @tag
end

#tag_listObject

Since:

  • 1.0.13



21
22
23
# File 'lib/support_readiness/gitlab/jobs.rb', line 21

def tag_list
  @tag_list
end

#userObject

Since:

  • 1.0.13



21
22
23
# File 'lib/support_readiness/gitlab/jobs.rb', line 21

def user
  @user
end

#web_urlObject

Since:

  • 1.0.13



21
22
23
# File 'lib/support_readiness/gitlab/jobs.rb', line 21

def web_url
  @web_url
end

Class Method Details

.find(client, project, jid) ⇒ Object

Locates a project job 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)
job = Readiness::GitLab::Jobs.find!(client, project, 5)
puts job.status
# => "failed"

Parameters:

  • client (Object)

    An instance of Client

  • project (Object)

    An instance of Projects

  • jid (Integer)

    The job IID to find

Returns:

  • (Object)

    An instance of {Readiness::GitLab::Jobs

See Also:

Author:

  • Jason Colyer

Since:

  • 1.0.13



155
156
157
158
159
160
161
# File 'lib/support_readiness/gitlab/jobs.rb', line 155

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

  Oj.load(response.body)
end

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

Lists all pipeline jobs. 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"])
jobs = Readiness::GitLab::Jobs.list_pipeline(client, pipeline, 1)
puts jobs.count
# => 100

Parameters:

  • client (Object)

    An instance of Client

  • pipeline (Object)

    An instance of Pipelines

  • 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



120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/support_readiness/gitlab/jobs.rb', line 120

def self.list_pipeline(client, pipeline, limit = 0, filters = [])
  array = []
  page = 1
  loop do
    response = client.connection.get "projects/#{pipeline.project_id}/pipelines/#{pipeline.iid}/jobs?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| Jobs.new(p) }
    break if body.count < 100
    break if limit != 0 && array.count >= (limit * 100)

    page += 1
  end
  array
end

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

Lists all project jobs. 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)
jobs = Readiness::GitLab::Jobs.list_project(client, project, 2)
puts jobs.count
# => 200

Parameters:

  • client (Object)

    An instance of Client

  • project (Object)

    An instance of Projects

  • 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



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/support_readiness/gitlab/jobs.rb', line 82

def self.list_project(client, project, limit = 0, filters = [])
  array = []
  page = 1
  loop do
    response = client.connection.get "projects/#{project.id}/jobs?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| Jobs.new(p) }
    break if body.count < 100
    break if limit != 0 && array.count >= (limit * 100)

    page += 1
  end
  array
end