2021-02-22 17:27:13 +05:30
#!/usr/bin/env ruby
# frozen_string_literal: true
require 'optparse'
2023-05-27 22:25:52 +05:30
require_relative 'base'
2021-02-22 17:27:13 +05:30
2023-05-27 22:25:52 +05:30
class CancelPipeline < Base
2021-02-22 17:27:13 +05:30
def initialize ( options )
2023-05-27 22:25:52 +05:30
super
2021-02-22 17:27:13 +05:30
@pipeline_id = options . delete ( :pipeline_id )
end
def execute
2021-10-27 15:23:28 +05:30
client . cancel_pipeline ( project , pipeline_id )
2021-02-22 17:27:13 +05:30
end
private
2023-05-27 22:25:52 +05:30
attr_reader :pipeline_id
2021-02-22 17:27:13 +05:30
end
2022-11-25 23:54:43 +05:30
if $PROGRAM_NAME == __FILE__
2021-10-27 15:23:28 +05:30
options = API :: DEFAULT_OPTIONS . dup
2021-02-22 17:27:13 +05:30
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
2021-10-27 15:23:28 +05:30
opts . on ( " -t " , " --api-token API_TOKEN " , String , " A value API token with the `api` scope " ) do | value |
2021-02-22 17:27:13 +05:30
options [ :api_token ] = value
end
2021-10-27 15:23:28 +05:30
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
2021-02-22 17:27:13 +05:30
opts . on ( " -h " , " --help " , " Prints this help " ) do
puts opts
exit
end
end . parse!
CancelPipeline . new ( options ) . execute
end