Class: SupportOps::GitLab::Pipelines

Inherits:
Base
  • Object
show all
Defined in:
lib/support_ops_gitlab/gitlab/pipelines.rb

Overview

TODO:

Document pipeline_variables

TODO:
TODO:
TODO:
TODO:

Document latest jobs

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

Author:

  • Jason Colyer

Since:

  • 1.0.0

Instance Attribute Summary collapse

Class Method Summary collapse

Methods inherited from Base

#activate!, #approve!, attributes, #badges, #ban!, #block!, client, #client=, #commits, configure, #contributors, #create_support_pin!, #deactivate!, define_attributes, #delete!, #diffs, #disable_2fa!, #discussions, #emails, #encoded_path, #events, #find, #find!, #gpg_keys, #hard_delete!, #impersonations, #initialize, #issues, #jobs, #latest_pipeline, #members, #memberships, #merge_requests, #move!, #notes, #paid?, #pats, #pipeline_variables, #pipelines, #preferences, #projects, readonly_attributes, #reject!, #revoke!, #rotate!, #save!, #ssh_keys, #store_original_attributes, #subscribe!, #support_pin, to_hash, #tokens, #unban!, #unblock!, #unsubscribe!, #webhooks

Constructor Details

This class inherits a constructor from SupportOps::GitLab::Base

Instance Attribute Details

#created_atString

XXX

Returns:

  • (String)

    the current value of created_at



34
35
36
# File 'lib/support_ops_gitlab/gitlab/pipelines.rb', line 34

def created_at
  @created_at
end

#idInteger

The ID of the pipeline

Returns:

  • (Integer)

    the current value of id



34
35
36
# File 'lib/support_ops_gitlab/gitlab/pipelines.rb', line 34

def id
  @id
end

#iidInteger

The integrated ID of the pipeline

Returns:

  • (Integer)

    the current value of iid



34
35
36
# File 'lib/support_ops_gitlab/gitlab/pipelines.rb', line 34

def iid
  @iid
end

#inputsHash

A hash containing the inputs, as key-value pairs, to use when creating the pipeline

Returns:

  • (Hash)

    the current value of inputs



34
35
36
# File 'lib/support_ops_gitlab/gitlab/pipelines.rb', line 34

def inputs
  @inputs
end

#nameString

The name of the pipeline

Returns:

  • (String)

    the current value of name



34
35
36
# File 'lib/support_ops_gitlab/gitlab/pipelines.rb', line 34

def name
  @name
end

#project_idInteger

The project the pipeline is on

Returns:

  • (Integer)

    the current value of project_id



34
35
36
# File 'lib/support_ops_gitlab/gitlab/pipelines.rb', line 34

def project_id
  @project_id
end

#refString

The branch or tag to run the pipeline on

Returns:

  • (String)

    the current value of ref



34
35
36
# File 'lib/support_ops_gitlab/gitlab/pipelines.rb', line 34

def ref
  @ref
end

#shaString

The SHA of the pipeline

Returns:

  • (String)

    the current value of sha



34
35
36
# File 'lib/support_ops_gitlab/gitlab/pipelines.rb', line 34

def sha
  @sha
end

#sourceString

The source of the pipeline

Returns:

  • (String)

    the current value of source



34
35
36
# File 'lib/support_ops_gitlab/gitlab/pipelines.rb', line 34

def source
  @source
end

#statusString

The status of the pipeline

Returns:

  • (String)

    the current value of status



34
35
36
# File 'lib/support_ops_gitlab/gitlab/pipelines.rb', line 34

def status
  @status
end

#updated_atString

The timestamp of when the pipeline was last updated

Returns:

  • (String)

    the current value of updated_at



34
35
36
# File 'lib/support_ops_gitlab/gitlab/pipelines.rb', line 34

def updated_at
  @updated_at
end

#variablesArray

An array of hashes containing the variables available in the pipeline

Returns:

  • (Array)

    the current value of variables



34
35
36
# File 'lib/support_ops_gitlab/gitlab/pipelines.rb', line 34

def variables
  @variables
end

#web_urlString

The URL the pipeline is at

Returns:

  • (String)

    the current value of web_url



34
35
36
# File 'lib/support_ops_gitlab/gitlab/pipelines.rb', line 34

def web_url
  @web_url
end

Class Method Details

.get(object) ⇒ Object

Locates a specific pipeline in a project

Examples:

require 'support_ops_gitlab'

SupportOps::GitLab::Configuration.configure do |config|
  config.url = 'https://gitlab.com/api/v4'
  config.token = 'abc123'
end

pipeline = SupportOps::GitLab::Pipelines.get(id: 987654, project_id: 123)
pp pipeline.name
# => "Awesome pipeline"
pp pipeline.id
# => 987654
pp pipeline.project_id
# => 123

See Also:

Author:

  • Jason Colyer

Since:

  • 1.0.0



169
170
171
172
173
174
175
176
177
# File 'lib/support_ops_gitlab/gitlab/pipelines.rb', line 169

def self.get(object)
  if object.is_a? Pipelines
    Pipelines.new(id: id, project_id: project_id).find
  elsif object.is_a? Hash
    Pipelines.new({ id: object[:id], project_id: object[:project_id] }).find
  else
    raise 'You need an id and a project_id attribute'
  end
end

.get!(object) ⇒ Object

Locates a specific pipeline in a project

Examples:

require 'support_ops_gitlab'

SupportOps::GitLab::Configuration.configure do |config|
  config.url = 'https://gitlab.com/api/v4'
  config.token = 'abc123'
end

pipeline = SupportOps::GitLab::Pipelines.get!(id: 987654, project_id: 123)
pp pipeline.name
# => "Awesome pipeline"
pp pipeline.id
# => 987654
pp pipeline.project_id
# => 123

See Also:

Author:

  • Jason Colyer

Since:

  • 1.0.0



203
204
205
206
207
208
209
210
211
# File 'lib/support_ops_gitlab/gitlab/pipelines.rb', line 203

def self.get!(object)
  if object.is_a? Pipelines
    Pipelines.new(id: id, project_id: project_id).find!
  elsif object.is_a? Hash
    Pipelines.new({ id: object[:id], project_id: object[:project_id] }).find!
  else
    raise 'You need an id and a project_id attribute'
  end
end

.list(key: value) ⇒ Array

Lists project pipelines

Examples:

require 'support_ops_gitlab'

SupportOps::GitLab::Configuration.configure do |config|
  config.url = 'https://gitlab.example.com/api/v4'
  config.token = 'abc123'
end

pipelines = SupportOps::GitLab::Pipelines.list(project_id: 123456)
pp pipelines.count
# => 30
pp pipelines.last.status
# => "pending"

Parameters:

  • project_id (Integer required)

    The project ID to get the pipelines from

  • created_after (String optional)

    Return pipelines created after the specified date; expected in ISO 8601 format (2019-03-15T08:00:00Z)

  • created_before (String optional)

    Return pipelines created before the specified date; expected in ISO 8601 format (2019-03-15T08:00:00Z)

  • name (String optional)

    Return pipelines with the specified name

  • order_by (String optional)

    Order pipelines by id, status, ref, updated_at or user_id

  • ref (String optional)

    The ref of pipelines

  • scope (String optional)

    The scope of pipelines, one of: running, pending, finished, branches, tags

  • sha (String optional)

    The SHA of pipelines

  • sort (String optional)

    Sort pipelines in asc or desc order

  • source (String optional)

    The pipeline source

  • status (String optional)

    The status of pipelines, one of: created, waiting_for_resource, preparing, pending, running, success, failed, canceled, skipped, manual, scheduled

  • updated_after (String optional)

    Return pipelines updated after the specified date; expected in ISO 8601 format (2019-03-15T08:00:00Z)

  • updated_before (String optional)

    Return pipelines updated before the specified date

  • username (String optional)

    The username of the user who triggered pipelines

  • yaml_errors (Boolean optional)

    Returns pipelines with invalid configurations

  • limit (Integer optional)

    The limit to the number of users returned. Default to 0 (i.e. no limit)

Returns:

  • (Array)

See Also:

Author:

  • Jason Colyer

Since:

  • 1.0.0



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'lib/support_ops_gitlab/gitlab/pipelines.rb', line 96

def self.list(**args)
  args[:project_id] = nil unless args[:project_id]
  raise 'You have to provide a project_id' if args[:project_id].nil?
  args[:created_after] = nil unless args[:created_after]
  args[:created_before] = nil unless args[:created_before]
  args[:name] = nil unless args[:name]
  args[:order_by] = nil unless args[:order_by]
  args[:ref] = nil unless args[:ref]
  args[:scope] = nil unless args[:scope]
  args[:sha] = nil unless args[:sha]
  args[:sort] = nil unless args[:sort]
  args[:source] = nil unless args[:source]
  args[:status] = nil unless args[:status]
  args[:updated_after] = nil unless args[:updated_after]
  args[:updated_before] = nil unless args[:updated_before]
  args[:username] = nil unless args[:username]
  args[:yaml_errors] = nil unless args[:yaml_errors]
  args[:limit] = 0 unless args[:limit]
  params = ''
  params += "created_after=#{args[:created_after]}&" unless args[:created_after].nil?
  params += "created_before=#{args[:created_before]}&" unless args[:created_before].nil?
  params += "name=#{args[:name]}&" unless args[:name].nil?
  params += "order_by=#{args[:order_by]}&" unless args[:order_by].nil?
  params += "ref=#{args[:ref]}&" unless args[:ref].nil?
  params += "scope=#{args[:scope]}&" unless args[:scope].nil?
  params += "sha=#{args[:sha]}&" unless args[:sha].nil?
  params += "sort=#{args[:sort]}&" unless args[:sort].nil?
  params += "source=#{args[:source]}&" unless args[:source].nil?
  params += "status=#{args[:status]}&" unless args[:status].nil?
  params += "updated_after=#{args[:updated_after]}&" unless args[:updated_after].nil?
  params += "updated_before=#{args[:updated_before]}&" unless args[:updated_before].nil?
  params += "username=#{args[:username]}&" unless args[:username].nil?
  params += "yaml_errors=#{args[:yaml_errors]}&" unless args[:yaml_errors].nil?
  array = []
  page = 1
  loop do
    response = client.connection.get("projects/#{args[:project_id]}/pipelines?#{params}&page=#{page}&per_page=100")
    body = Oj.load(response.body)
    array += body.map { |p| Pipelines.new(p) }
    break if args[:limit].to_i.positive? && array.count >= args[:limit].to_i
    break if body.count < 100

    page += 1
  end
  return array if args[:limit].to_i.zero?
  
  array.first(args[:limit].to_i)
end