- Cancel all running pipelines and their jobs
- Cancel stuck pending pipelines
- Try merge request integration
- Validate the
.gitlab-ci.yml
file - Disable AutoDevOps on Existing Projects
- Run pipeline schedules manually
- Obtain runners registration token (deprecated)
- Seed runners registration token (deprecated)
CI/CD maintenance console commands
{{< details >}}
- Tier: Free, Premium, Ultimate
- Offering: GitLab Self-Managed
{{< /details >}}
The following commands are run in the Rails console.
{{< alert type=”warning” >}}
Any command that changes data directly could be damaging if not run correctly, or under the right conditions. We highly recommend running them in a test environment with a backup of the instance ready to be restored, just in case.
{{< /alert >}}
Cancel all running pipelines and their jobs
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
Cancel stuck pending pipelines
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
Try merge request integration
project = Project.find_by_full_path('<project_path>')
mr = project.merge_requests.find_by(iid: <merge_request_iid>)
mr.project.try(:ci_integration)
Validate the .gitlab-ci.yml
file
project = Project.find_by_full_path('<project_path>')
content = project.ci_config_for(project.repository.root_ref_sha)
Gitlab::Ci::Lint.new(project: project, current_user: User.first).validate(content)
Disable AutoDevOps on Existing Projects
Project.all.each do |p|
p.auto_devops_attributes={"enabled"=>"0"}
p.save
end
Run pipeline schedules manually
You can run pipeline schedules manually through the Rails console to reveal any errors that are usually not visible.
# 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)
Obtain runners registration token (deprecated)
{{< alert type=”warning” >}}
The option to pass runner registration tokens and support for certain configuration arguments are deprecated in GitLab 15.6 and is planned for removal in GitLab 20.0. Use the runner creation workflow to generate an authentication token to register runners. This process provides full traceability of runner ownership and enhances your runner fleet’s security. For more information, see Migrating to the new runner registration workflow.
{{< /alert >}}
Prerequisites:
- Runner registration tokens must be enabled in the Admin area.
Gitlab::CurrentSettings.current_application_settings.runners_registration_token
Seed runners registration token (deprecated)
{{< alert type=”warning” >}}
The option to pass runner registration tokens and support for certain configuration arguments are deprecated in GitLab 15.6 and is planned for removal in GitLab 20.0. Use the runner creation workflow to generate an authentication token to register runners. This process provides full traceability of runner ownership and enhances your runner fleet’s security. For more information, see Migrating to the new runner registration workflow.
{{< /alert >}}
appSetting = Gitlab::CurrentSettings.current_application_settings
appSetting.set_runners_registration_token('<new-runners-registration-token>')
appSetting.save!