diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-12-10 15:07:55 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-12-10 15:07:55 +0300 |
commit | 5e11c9b77cb1b2b77ee29359047b55807afe255d (patch) | |
tree | 40b02dead6acdcaab9cc15efc9ae4710c2ed78a8 /scripts/get-job-id | |
parent | 97d4d926630822d0e1a638206909679c962d2f0a (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'scripts/get-job-id')
-rwxr-xr-x | scripts/get-job-id | 43 |
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 |