This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
This is a Ruby CLI toolkit for managing GitLab projects. It includes tools for exporting/importing CI/CD variables and removing job artifacts.
Single-file CLIs: Both gitlab_variable_editor and gitlab_artifact_remover are standalone Thor-based scripts.
Key dependencies:
gitlabgem (v4.19+) - GitLab API clientthorgem (v1.3+) - CLI framework- Standard library:
yaml,time,uri
Core flow (Variable Editor):
GitLabVariableEditorclass inherits fromThor- Global options (
--endpoint,--token,--project) are defined as class options - Two commands:
exportandimport - Private method
configure_clientinitializes the Gitlab client with user credentials
Core flow (Artifact Remover):
GitLabArtifactRemoverclass inherits fromThor- Same global options as the variable editor
- One command:
removewith--older-thanand--forceoptions - Uses
auto_paginateto iterate through all jobs - Filters jobs by checking
artifactsarray forfile_type == 'archive' - Deletes artifacts via raw
client.deleteAPI call to/projects/:id/jobs/:job_id/artifacts
Install dependencies:
bundle installExport variables (command must come BEFORE options):
./gitlab_variable_editor export output.yml \
-e https://gitlab.example.com/api/v4 \
-t glpat-xxxxxxxxxxxxxxxxxxxx \
-p my-group/my-projectImport variables:
./gitlab_variable_editor import input.yml \
-e https://gitlab.example.com/api/v4 \
-t glpat-xxxxxxxxxxxxxxxxxxxx \
-p my-group/my-projectForce import (skip confirmation):
./gitlab_variable_editor import input.yml -e ... -t ... -p ... --forceRemove artifacts older than 3 days:
./gitlab_artifact_remover remove \
-e https://gitlab.example.com/api/v4 \
-t glpat-xxxxxxxxxxxxxxxxxxxx \
-p my-group/my-project \
--older-than 3dForce artifact removal (skip confirmation):
./gitlab_artifact_remover remove -e ... -t ... -p ... --older-than 3d --forceTest commands:
./gitlab_variable_editor help
./gitlab_variable_editor help export
./gitlab_variable_editor help import
./gitlab_artifact_remover help
./gitlab_artifact_remover help removeVariables are stored as an array of hashes with these keys:
key- Variable name (required)value- Variable value (required)variable_type-env_varorfile(default:env_var)protected- Boolean (default: false)masked- Boolean (default: false)hidden- Boolean (default: false, GitLab 17.4+)raw- Boolean (default: false)environment_scope- String (default:*)description- String (optional)
See example-variables.yml for a complete example.
Authentication: Uses Gitlab.client() with endpoint and private token.
Key API methods (from gitlab gem):
@client.variables(project_id)- List all variables@client.create_variable(project_id, key, value, options)- Create variable@client.update_variable(project_id, key, value, options)- Update variable@client.jobs(project_id, options)- List jobs (with pagination)@client.delete(path)- Raw DELETE request (used for artifact removal)
Artifact removal API endpoint:
DELETE /projects/:id/jobs/:job_id/artifacts- Delete artifacts for a specific job
Error handling: All GitLab API calls are wrapped in begin/rescue blocks catching Gitlab::Error::Error.
- Thor argument order: Commands must come before options. Wrong:
./tool -e X export file. Right:./tool export file -e X. - Sensitive data: Exported YAML files contain secrets. The
.gitignoreexcludes*.ymland*.yamlexceptexample-variables.yml. - Token requirements: GitLab personal access token needs
apiscope for full variable management and artifact removal. - User confirmation: Import and artifact removal show a summary and require user input (
yes/y) before proceeding, unless--forceis used. - Artifact filtering: The artifact remover checks for
file_type == 'archive'in the job'sartifactsarray to distinguish real artifacts from job traces (logs).