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

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/api/cancel_pipeline.rb')
-rwxr-xr-xscripts/api/cancel_pipeline.rb30
1 files changed, 13 insertions, 17 deletions
diff --git a/scripts/api/cancel_pipeline.rb b/scripts/api/cancel_pipeline.rb
index f3aea90f54f..2de50dcee80 100755
--- a/scripts/api/cancel_pipeline.rb
+++ b/scripts/api/cancel_pipeline.rb
@@ -1,40 +1,32 @@
#!/usr/bin/env ruby
# frozen_string_literal: true
-require 'rubygems'
require 'gitlab'
require 'optparse'
-require_relative 'get_job_id'
+require_relative 'default_options'
class CancelPipeline
- DEFAULT_OPTIONS = {
- project: ENV['CI_PROJECT_ID'],
- pipeline_id: ENV['CI_PIPELINE_ID'],
- # Default to "CI scripts API usage" at https://gitlab.com/gitlab-org/gitlab/-/settings/access_tokens
- api_token: ENV['PROJECT_TOKEN_FOR_CI_SCRIPTS_API_USAGE']
- }.freeze
-
def initialize(options)
@project = options.delete(:project)
@pipeline_id = options.delete(:pipeline_id)
- Gitlab.configure do |config|
- config.endpoint = 'https://gitlab.com/api/v4'
- config.private_token = options.delete(:api_token)
- end
+ @client = Gitlab.client(
+ endpoint: options.delete(:endpoint) || API::DEFAULT_OPTIONS[:endpoint],
+ private_token: options.delete(:api_token)
+ )
end
def execute
- Gitlab.cancel_pipeline(project, pipeline_id)
+ client.cancel_pipeline(project, pipeline_id)
end
private
- attr_reader :project, :pipeline_id
+ attr_reader :project, :pipeline_id, :client
end
if $0 == __FILE__
- options = CancelPipeline::DEFAULT_OPTIONS.dup
+ 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|
@@ -45,10 +37,14 @@ if $0 == __FILE__
options[:pipeline_id] = value
end
- opts.on("-t", "--api-token API_TOKEN", String, "A value API token with the `read_api` scope") do |value|
+ 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