Skip to content
代码片段 群组 项目
提交 ee30ca7a 编辑于 作者: Lin Jen-Shin's avatar Lin Jen-Shin
浏览文件

Merge branch 'trigger-downstream-pipelines-against-stable-branch-automatically' into 'master'

Automatically trigger downstream pipelines against stable branches

See merge request gitlab-org/gitlab!83602
No related branches found
No related tags found
无相关合并请求
...@@ -83,7 +83,7 @@ def simple_forwarded_variables ...@@ -83,7 +83,7 @@ def simple_forwarded_variables
# Override to trigger and work with pipeline on different GitLab instance # Override to trigger and work with pipeline on different GitLab instance
# type: :downstream -> downstream build and pipeline status # type: :downstream -> downstream build and pipeline status
# type: :upstream -> this project, e.g. for posting comments # type: :upstream -> this project, e.g. for posting comments
def gitlab_client(type) def gitlab_client(_type)
# By default, always use the same client # By default, always use the same client
@gitlab_client ||= Gitlab.client( @gitlab_client ||= Gitlab.client(
endpoint: 'https://gitlab.com/api/v4', endpoint: 'https://gitlab.com/api/v4',
...@@ -97,10 +97,15 @@ def downstream_project_path ...@@ -97,10 +97,15 @@ def downstream_project_path
end end
# Must be overridden # Must be overridden
def ref def ref_param_name
raise NotImplementedError raise NotImplementedError
end end
# Can be overridden
def primary_ref
'main'
end
# Can be overridden # Can be overridden
def trigger_token def trigger_token
ENV['CI_JOB_TOKEN'] ENV['CI_JOB_TOKEN']
...@@ -116,6 +121,27 @@ def version_param_value(version_file) ...@@ -116,6 +121,27 @@ def version_param_value(version_file)
ENV[version_file]&.strip || File.read(version_file).strip ENV[version_file]&.strip || File.read(version_file).strip
end end
# Can be overridden
def trigger_stable_branch_if_detected?
false
end
def stable_branch?
ENV['CI_COMMIT_REF_NAME'] =~ /^[\d-]+-stable(-ee)?$/
end
def fallback_ref
if trigger_stable_branch_if_detected? && stable_branch?
ENV['CI_COMMIT_REF_NAME'].delete_suffix('-ee')
else
primary_ref
end
end
def ref
ENV.fetch(ref_param_name, fallback_ref)
end
def base_variables def base_variables
# Use CI_MERGE_REQUEST_SOURCE_BRANCH_SHA for omnibus checkouts due to pipeline for merged results, # Use CI_MERGE_REQUEST_SOURCE_BRANCH_SHA for omnibus checkouts due to pipeline for merged results,
# and fallback to CI_COMMIT_SHA for the `detached` pipelines. # and fallback to CI_COMMIT_SHA for the `detached` pipelines.
...@@ -146,8 +172,16 @@ def downstream_project_path ...@@ -146,8 +172,16 @@ def downstream_project_path
ENV.fetch('OMNIBUS_PROJECT_PATH', 'gitlab-org/build/omnibus-gitlab-mirror') ENV.fetch('OMNIBUS_PROJECT_PATH', 'gitlab-org/build/omnibus-gitlab-mirror')
end end
def ref def ref_param_name
ENV.fetch('OMNIBUS_BRANCH', 'master') 'OMNIBUS_BRANCH'
end
def primary_ref
'master'
end
def trigger_stable_branch_if_detected?
true
end end
def extra_variables def extra_variables
...@@ -184,10 +218,16 @@ def variables ...@@ -184,10 +218,16 @@ def variables
private private
def ref def ref_param_name
return ENV['CI_COMMIT_REF_NAME'] if ENV['CI_COMMIT_REF_NAME'] =~ /^[\d-]+-stable(-ee)?$/ 'CNG_BRANCH'
end
def primary_ref
'master'
end
ENV.fetch('CNG_BRANCH', 'master') def trigger_stable_branch_if_detected?
true
end end
def extra_variables def extra_variables
...@@ -272,8 +312,8 @@ def downstream_project_path ...@@ -272,8 +312,8 @@ def downstream_project_path
ENV.fetch('DOCS_PROJECT_PATH', 'gitlab-org/gitlab-docs') ENV.fetch('DOCS_PROJECT_PATH', 'gitlab-org/gitlab-docs')
end end
def ref def ref_param_name
ENV.fetch('DOCS_BRANCH', 'main') 'DOCS_BRANCH'
end end
# `gitlab-org/gitlab-docs` pipeline trigger "Triggered from gitlab-org/gitlab 'review-docs-deploy' job" # `gitlab-org/gitlab-docs` pipeline trigger "Triggered from gitlab-org/gitlab 'review-docs-deploy' job"
...@@ -377,8 +417,12 @@ def extra_variables ...@@ -377,8 +417,12 @@ def extra_variables
} }
end end
def ref def ref_param_name
ENV['GITLABCOM_DATABASE_TESTING_TRIGGER_REF'] || 'master' 'GITLABCOM_DATABASE_TESTING_TRIGGER_REF'
end
def primary_ref
'master'
end end
end end
......
此差异已折叠。
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册