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/download_job_artifact.rb')
-rwxr-xr-xscripts/api/download_job_artifact.rb19
1 files changed, 9 insertions, 10 deletions
diff --git a/scripts/api/download_job_artifact.rb b/scripts/api/download_job_artifact.rb
index d725de3f1b6..23202ad3912 100755
--- a/scripts/api/download_job_artifact.rb
+++ b/scripts/api/download_job_artifact.rb
@@ -1,31 +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'],
- # 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)
@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))
@@ -37,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
@@ -66,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|
@@ -85,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