- 取消所有运行中的流水线及其作业
- 取消卡住的待处理流水线
- 尝试合并请求集成
- 验证
.gitlab-ci.yml
文件 - 禁用现有项目上的 AutoDevOps
- 手动运行流水线计划
- 获取 runners 注册令牌(已弃用)
- 种子 runners 注册令牌(已弃用)
CI/CD 维护控制台命令
以下命令在 Rails 控制台 中运行。
任何直接更改数据的命令如果未正确运行或在适当的条件下运行,可能会造成损害。我们强烈建议在测试环境中运行这些命令,并准备好实例的备份以便在必要时恢复。
取消所有运行中的流水线及其作业
admin = User.find(user_id) # replace user_id with the id of the admin you want to cancel the pipeline
# Iterate over each cancelable pipeline
Ci::Pipeline.cancelable.find_each do |pipeline|
Ci::CancelPipelineService.new(
pipeline: pipeline,
current_user: user,
cascade_to_children: false # the children are included in the outer loop
)
end
取消卡住的待处理流水线
project = Project.find_by_full_path('<project_path>')
Ci::Pipeline.where(project_id: project.id).where(status: 'pending').count
Ci::Pipeline.where(project_id: project.id).where(status: 'pending').each {|p| p.cancel if p.stuck?}
Ci::Pipeline.where(project_id: project.id).where(status: 'pending').count
尝试合并请求集成
project = Project.find_by_full_path('<project_path>')
mr = project.merge_requests.find_by(iid: <merge_request_iid>)
mr.project.try(:ci_integration)
验证 .gitlab-ci.yml
文件
project = Project.find_by_full_path('<project_path>')
content = p.ci_config_for(project.repository.root_ref_sha)
Gitlab::Ci::Lint.new(project: project, current_user: User.first).validate(content)
禁用现有项目上的 AutoDevOps
Project.all.each do |p|
p.auto_devops_attributes={"enabled"=>"0"}
p.save
end
手动运行流水线计划
您可以通过 Rails 控制台手动运行流水线计划,以发现通常不明显的错误。
# schedule_id can be obtained from Edit Pipeline Schedule page
schedule = Ci::PipelineSchedule.find_by(id: <schedule_id>)
# Select the user that you want to run the schedule for
user = User.find_by_username('<username>')
# Run the schedule
ps = Ci::CreatePipelineService.new(schedule.project, user, ref: schedule.ref).execute!(:schedule, ignore_skip_ci: true, save_on_errors: false, schedule: schedule)
获取 runners 注册令牌(已弃用)
传递 runner 注册令牌的能力以及对某些配置参数的支持在极狐GitLab 15.6 中已被弃用,并计划在极狐GitLab 18.0 中移除。应该使用 runner 身份验证令牌。有关更多信息,请参见迁移到新的 runner 注册工作流程。
先决条件:
- 必须在 Admin 区域启用 runner 注册令牌。
Gitlab::CurrentSettings.current_application_settings.runners_registration_token
种子 runners 注册令牌(已弃用)
传递 runner 注册令牌的能力以及对某些配置参数的支持在极狐GitLab 15.6 中已被弃用,并计划在极狐GitLab 18.0 中移除。应该使用 runner 身份验证令牌。有关更多信息,请参见迁移到新的 runner 注册工作流程。
appSetting = Gitlab::CurrentSettings.current_application_settings
appSetting.set_runners_registration_token('<new-runners-registration-token>')
appSetting.save!