Gitlab Assistant is your cheerful command-line sidekick for wrangling GitLab automation tasks with ease 💪. It currently ships with helper scripts for exporting and importing CI/CD variables, and it is built to grow 🪴 as more everyday chores get scripted away.
- Keep CI/CD secrets backed up safely ✅
- Sync configuration between projects or environments 🔄
- Automate routine GitLab chores without clicking through the UI 🖱️➡️⌨️
- Provide a foundation for future GitLab helpers 🧱
Prerequisites
- Python 3.9 or newer 🐍
- Access to a GitLab instance with API permissions 🔐
- Optional:
pip install -r requirements.txt(if you split dependencies later) 📦
Quick Setup
- Clone the repository ☁️⬇️
- Create a virtual environment (recommended) 🌀
- Install dependencies such as
requestsandpyyaml📚 - Copy
.env.exampleto.env(if present) and fill in credentials 🔑
python3 -m venv .venv
source .venv/bin/activate
pip install requests pyyamlTip: Add new helper libraries to a future
requirements.txtso teammates can sync quickly 🌈
The scripts look for GitLab credentials in this order:
- Command-line arguments (
--token,--username,--password) 🧾 - Environment variables (
GITLAB_TOKEN,GITLAB_USERNAME,GITLAB_PASSWORD) 🌍 - Values loaded from a
.envfile 💼
You can mix and match—provide a token flag for one-off runs or keep reusable secrets in .env (never commit secrets! 🙅♂️).
Exports CI/CD variables for a given project (and optionally its parent groups) into a tidy YAML snapshot.
Highlights
- Supports project URLs or
@https://...shorthand ✂️ - Loads
.envautomatically to keep your shell clean 🧽 - Falls back to username/password authentication by trading them for a temporary token 💳
- Fetches group-level inherited variables when
--include-groupsis set 🧬 - Writes YAML using PyYAML if available, or a built-in fallback ✍️
Core Flow
- Parse the project URL and break it into base URL + project path 🔍
- Load credentials from CLI/env/.env 🔑
- Create an authenticated
requests.Session🕸️ - Paginate through
/variablesendpoints for project (and groups if requested) 📦 - Assemble everything into a normalized JSON-like structure 🧱
- Dump the result to
output/<project>-cicd-variables.yaml(auto-creates the folder) 📂
Usage
./gitlab-cicd-variables-export.py @https://gitlab.example.com/team/awesome-service \
--include-groups \
--output awesome-service-prod.yamlOutputs look like:
project: team/awesome-service
variables:
- key: API_TOKEN
value: "..."
source: project
masked: true
# ...Imports CI/CD variables from the YAML format produced by the export script, safely updating or creating entries.
Highlights
- Validates the target project matches the YAML metadata (warns if not)
⚠️ - Reuses the same authentication mechanisms as the exporter 🔄
- Upserts each variable with smart retry logic (create → update fallback) 🧠
- Handles group variables unless
--skip-groupsis set 🚫 - Offers
--dry-runto preview actions without touching GitLab 🔍
Core Flow
- Parse CLI arguments and resolve credentials 🛠️
- Load the YAML document via PyYAML 📖
- Iterate over project entries, validating schema 🔐
- Upsert each variable into
/projects/.../variables🧱 - Repeat for
group_variablesunless dry-run/skip is requested 🔁 - Summarize created/updated/failed counts 📊
Usage
./gitlab-cicd-variables-import.py @https://gitlab.example.com/team/awesome-service \
output/awesome-service-prod.yaml \
--dry-runWhen ready for the real run, drop --dry-run to apply changes for real ✅
- Always prefer absolute paths when scripting to avoid surprises 🚫🪄
- Store generated YAML in the
output/directory 🎯 - Keep type hints and docstrings—new scripts should follow the same style 👩💻
- Wrap network calls with humble error handling and descriptive messages 🧯
- 🔍 Discover pipeline schedules and manage them from the CLI
- 🧪 Trigger test pipelines with temporary variables for feature branches
- 🧰 Abstract common helpers into a shared module to reduce duplication
- 🧾 Generate Markdown reports of environment differences
Feel free to add your own ideas by extending this list—Gitlab Assistant loves new skills! 🤩
- Fork or branch, then open a merge request 🪜
- Add docs and examples when introducing new scripts 📝
- Keep emoji energy high—it keeps the bots happy 😄
Choose a license that suits the project and document it here once decided (MIT, Apache-2.0, etc.). Until then, treat it as proprietary/private. 🛡️
Happy automating! ⚙️✨