Method: Gitlab::Client::Pipelines#create_pipeline

Defined in:
lib/gitlab/client/pipelines.rb

#create_pipeline(project, ref, variables = {}) ⇒ Gitlab::ObjectifiedHash

Create a pipeline.

Examples:

Gitlab.create_pipeline(5, 'master')

Parameters:

  • project (Integer, String)

    The ID or name of a project.

  • ref (String)

    Reference to commit.

  • variables (Hash) (defaults to: {})

    Variables passed to pipelines

Returns:

[View source]

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

def create_pipeline(project, ref, variables = {})
  body = {}

  # This mapping is necessary, cause the API expects an array with objects (with `key` and `value` keys)
  # See: https://docs.gitlab.com/ee/api/pipelines.html#create-a-new-pipeline
  body[:variables] = variables.map { |(key, value)| { key: key, value: value } } if variables.any?

  post(
    "/projects/#{url_encode project}/pipeline",
    query: { ref: ref },
    body: body
  )
end