Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cancel_pipeline.rb « api « scripts - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 2de50dcee80c1b42376e116c5abaac59343c05cf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/env ruby
# frozen_string_literal: true

require 'gitlab'
require 'optparse'
require_relative 'default_options'

class CancelPipeline
  def initialize(options)
    @project = options.delete(:project)
    @pipeline_id = options.delete(:pipeline_id)

    @client = Gitlab.client(
      endpoint: options.delete(:endpoint) || API::DEFAULT_OPTIONS[:endpoint],
      private_token: options.delete(:api_token)
    )
  end

  def execute
    client.cancel_pipeline(project, pipeline_id)
  end

  private

  attr_reader :project, :pipeline_id, :client
end

if $0 == __FILE__
  options = API::DEFAULT_OPTIONS.dup

  OptionParser.new do |opts|
    opts.on("-p", "--project PROJECT", String, "Project where to find the job (defaults to $CI_PROJECT_ID)") do |value|
      options[:project] = value
    end

    opts.on("-i", "--pipeline-id PIPELINE_ID", String, "A pipeline ID (defaults to $CI_PIPELINE_ID)") do |value|
      options[:pipeline_id] = value
    end

    opts.on("-t", "--api-token API_TOKEN", String, "A value API token with the `api` scope") do |value|
      options[:api_token] = value
    end

    opts.on("-E", "--endpoint ENDPOINT", String, "The API endpoint for the API token. (defaults to $CI_API_V4_URL and fallback to https://gitlab.com/api/v4)") do |value|
      options[:endpoint] = value
    end

    opts.on("-h", "--help", "Prints this help") do
      puts opts
      exit
    end
  end.parse!

  CancelPipeline.new(options).execute
end