summaryrefslogtreecommitdiff
path: root/scripts/api/download_job_artifact.rb
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/api/download_job_artifact.rb')
-rwxr-xr-xscripts/api/download_job_artifact.rb18
1 files changed, 9 insertions, 9 deletions
diff --git a/scripts/api/download_job_artifact.rb b/scripts/api/download_job_artifact.rb
index 8e2207c6fa7..23202ad3912 100755
--- a/scripts/api/download_job_artifact.rb
+++ b/scripts/api/download_job_artifact.rb
@@ -1,30 +1,26 @@
#!/usr/bin/env ruby
# frozen_string_literal: true
-require 'rubygems'
require 'optparse'
require 'fileutils'
require 'uri'
require 'cgi'
require 'net/http'
+require_relative 'default_options'
class ArtifactFinder
- DEFAULT_OPTIONS = {
- project: ENV['CI_PROJECT_ID'],
- api_token: ENV['GITLAB_BOT_MULTI_PROJECT_PIPELINE_POLLING_TOKEN']
- }.freeze
-
def initialize(options)
@project = options.delete(:project)
@job_id = options.delete(:job_id)
@api_token = options.delete(:api_token)
+ @endpoint = options.delete(:endpoint) || API::DEFAULT_OPTIONS[:endpoint]
@artifact_path = options.delete(:artifact_path)
warn "No API token given." unless api_token
end
def execute
- url = "https://gitlab.com/api/v4/projects/#{CGI.escape(project)}/jobs/#{job_id}/artifacts"
+ url = "#{endpoint}/projects/#{CGI.escape(project)}/jobs/#{job_id}/artifacts"
if artifact_path
FileUtils.mkdir_p(File.dirname(artifact_path))
@@ -36,7 +32,7 @@ class ArtifactFinder
private
- attr_reader :project, :job_id, :api_token, :artifact_path
+ attr_reader :project, :job_id, :api_token, :endpoint, :artifact_path
def fetch(uri_str, limit = 10)
raise 'Too many HTTP redirects' if limit == 0
@@ -65,7 +61,7 @@ class ArtifactFinder
end
if $0 == __FILE__
- options = ArtifactFinder::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|
@@ -84,6 +80,10 @@ if $0 == __FILE__
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