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/get-job-id')
-rwxr-xr-xscripts/get-job-id43
1 files changed, 43 insertions, 0 deletions
diff --git a/scripts/get-job-id b/scripts/get-job-id
new file mode 100755
index 00000000000..a5d34dc545b
--- /dev/null
+++ b/scripts/get-job-id
@@ -0,0 +1,43 @@
+#!/usr/bin/env ruby
+# frozen_string_literal: true
+
+require 'gitlab'
+require 'optparse'
+
+#
+# Configure credentials to be used with gitlab gem
+#
+Gitlab.configure do |config|
+ config.endpoint = 'https://gitlab.com/api/v4'
+ config.private_token = ENV['GITLAB_BOT_MULTI_PROJECT_PIPELINE_POLLING_TOKEN']
+end
+
+options = {}
+OptionParser.new do |opts|
+ opts.on("-s", "--scope=SCOPE", "Find job with matching scope") do |scope|
+ options[:scope] = scope
+ end
+end.parse!
+
+class PipelineJobFinder
+ def initialize(project_id, pipeline_id, job_name, options)
+ @project_id = project_id
+ @pipeline_id = pipeline_id
+ @job_name = job_name
+ @options = options
+ end
+
+ def execute
+ Gitlab.pipeline_jobs(@project_id, @pipeline_id, @options).auto_paginate do |job|
+ break job if job.name == @job_name
+ end
+ end
+end
+
+project_id, pipeline_id, job_name = ARGV
+
+job = PipelineJobFinder.new(project_id, pipeline_id, job_name, options).execute
+
+return if job.nil?
+
+puts job.id